If you create a widget which links back to content on the Drupal site there needs to be a way of breaking out of the iframe.

For example, say you create a widget that displays the photos of the latest 5 people to join your site. You would expect to click on a picture a new browser window to open and either the profile to be displayed or some kind of sign-in.

The problem at the moment is that all the links will open within the iframe. It would be good if embed_widgets had an option to add a <base target="_blank"/> tag into the <head> that the embed script generates. This would ensure that all links in the widget open a new window when a user clicks on them.

Good luck with this great module! :)
Paul

Comments

jtsnow’s picture

This is definitely on my to-do list! I have been playing with the idea of opening some links in a new tab within the widget, but I most likely won't have time to do that during Summer of Code. So I will be implementing it as you said: all links in the will open a new window.

nedjo’s picture

There's some commented out code in embed_widgets.js that was a first rough cut at how to handle this issue.


        // Open node and external links in a new window.
        //if ((href.indexOf('node/') != -1) || (href.indexOf('://') != -1)) {
        //  // $(this).attr('target', '_parent');
        //  $(this).attr('target', '_blank');
        //}

The idea here was to make certain links open normally and others (absolute links, links to /node/x) open in a new window.

The problem, though, is how to decide which relative links should open in a new window. Testing for the string 'node/' breaks as soon as url aliases are in use, and in any case there are many other internal links that will best be opened in a new window.

One possibility would be to approach this on the server side, using a regex to filter all links before the rendered page is returned, selectively adding e.g. the target="_blank". E.g., have a configuration option like the one used for block path filtering, where an admin enters paths (with wildcards) to be matched, and matched paths (or unmatched ones) get the target attribute.

freshaspect’s picture

The easiest way I found to get this working was to edit embed_widgets_iframe_page.tpl.php and add the <base target = "_blank"/> tag at the top as follows:

<head>
  <title><?php  print $content["title"] ?></title>
  <?php print $content["head"] ?>
  <?php print $content["scripts"] ?>
  <?php //print $page["robots_meta"] ?>
  <?php print $content["css"] ?>
  <base target = "_blank"/>
</head>

Works perfectly for me which is cool!

jtsnow’s picture

Version: 6.x-1.x-dev » 6.x-2.0-alpha1
Status: Active » Fixed

Latest version allows users to specify which paths to open in new windows and which ones should remain in the iframe.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.