How can I open all external links in the same new window?

Something like this...
Users navigate my website at windows A. User clicks on an external link. which loads the page in a new window, window B. User clicks on another external link and it also gets loaded in window B, and so on. No matter how many external link the user clicks, there will be only 2 windows open, one window A where my webpage will be loaded and one more window B where the external link will be loaded.

How can I accomplish this with this module?

Thank you...

#22 extlink_target_rollback.patch2.54 KBquicksketch
#12 extlink-1304464-12.patch1.78 KBelachlan
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch extlink-1304464-12.patch. Unable to apply patch. See the log in the details link for more information. View


quicksketch’s picture

Category: support » feature

Right now External Links module is hard-coded to open all links in a new window (a target of "_blank"). We could make an option to set the "target" attribute to a particular value which would have the effect you're describing.

Mel55113’s picture

I would like very much to be able to use an option to set the target name. Currently I hack the module to specify a target name.

hgurol’s picture


Can you please share your hack.


elachlan’s picture

Title: Open Ex. Links in a Certain Windows » Add option to set "target" attribute
Mel55113’s picture

It's really pretty simple. Search for "_blank" in the file extlink.module; replace it with a target name of your choice, e.g., "mytarget". There are two occurrences, somewhere around lines 73 and 81.

elachlan’s picture

If we were to add an option, Id like to give a choice rather than let the user set their own. Otherwise you open the possibility to inject html.

Mel55113 - Are you changing your target to a specific name or just to a normal target?

Link for Reference:

Mel55113’s picture

I set a specific target, what would be called a framename in the referenced page. I would like to be able to set the target uniquely for each site, e.g., for I might use client-ext as the target name, for I would use client2-ext.

I'm not an expert in this area but a specified string could be cleaned in the same manner that node titles are cleaned. Or, the specified target name could be limited to simply alpha, numeric, hyphen ("-"), and underscore ("_") characters. Or, the length could be limited, e.g., maybe 8 characters. That would, I believe, prevent html injection. Also, the setting the option requires authority to alter the site configuration, something that should not be freely granted.

Hope this helps,

elachlan’s picture

Title: Add option to set "target" attribute » Add option to set "target" attribute. Open all links in single window.

You are correct Mel55113.

I will look into it, unless you want to submit a patch.

Mel55113’s picture

Thank you! I'm not enough of a PHP programmer to create a patch :(.

elachlan’s picture

I suggest we do it the same as "Display a pop-up warning when any external link is clicked."

Although this method will not work in 6.x.

Mel55113’s picture

That would be fine.

Actually, I don't know why it wouldn't work with Drupal 6 but I don't think it's worth the effort at this stage in D6's life.

elachlan’s picture

Status: Active » Needs review
1.78 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch extlink-1304464-12.patch. Unable to apply patch. See the log in the details link for more information. View

First go at a patch. This should work I think.

Mel55113’s picture

I manually applied the patch (sorry, Windows here :(). It works!

Thanks very much,

Status: Needs review » Needs work

The last submitted patch, extlink-1304464-12.patch, failed testing.

elachlan’s picture

Status: Needs work » Patch (to be ported)

Committed to GIT! Will need to port to 6.x and 8.x.’s picture

Issue summary: View changes

FYI, ever since I upgraded from 7.x-1.13 to 7.x-1.16, the module all of a sudden stopped opening external links in a new window. But all I had to do to fix this was to go to settings and just click "Save configuration" without making any changes and it started working again. YMMV.

roball’s picture

Version: 7.x-1.12 » 7.x-1.16
Status: Patch (to be ported) » Needs work

Same here as reported in #16, thus changing the Status.

DeNelo’s picture

#16 #17: Me too. Suddenly my regexps failed. I used to be able to include the following as an external link:
Now I have to escape the first slash:
This change in behaviour is not documented in the release notes. But I guess I was just lucky to get away with the regexp without escaping the slash in the first place...

quicksketch’s picture

Status: Needs work » Closed (fixed)

Thanks guys, the patch at #2248803: Needed to re-save config options to get "open in new window" to work will solve this problem per #16 and #17. @DeNelo: That sounds like another issue yet, as this issue is about the target attribute option, not the regexs.

quicksketch’s picture

Status: Closed (fixed) » Active

Actually, on further thought, I think we should simply rollback this entire patch. It was decided when we first wrote the module that providing a textfield for this option was too much granularity. If you want to change this to open in a single window, you can put the value hard-coded in settings.php:

$conf['extlink_target'] = 'my_window_name';

This provided the option for the 1% use-case while simplifying the option for everyone else.

elachlan’s picture

Sounds good.

There seems to be a lot of requests for small features that make the module more complex.

I think it is best to keep it as simple as possible.

quicksketch’s picture

Status: Active » Fixed
2.54 KB

This rolls back this change in configuration options. Users needing to open all links in the same window should use the approach described in #20 to hard-code a window name in settings.php.

  • Commit 866ec66 on 7.x-1.x by quicksketch:
    Issue #1304464: Rollback extlink target custom window name option.
Mel55113’s picture

I think the decision to rollback this useful function was very shortsighted!

My experience was that the change worked as I wanted and expected. Should another sitebuilder wish to not specify a custom target name, then the default worked just fine.

EVERY one of the sites I build has custom options specified through various configuration pages. NONE of my current sites set any configuration options using settings.php. I am certain that I represent the VAST MAJORITY of Drupal site developers.

This is a very useful function. Having a configuration option serves builders like me very well and DOES NOT complicate site administration for any other users. Also, having the ability to configure the target through a configuration setting provided by the module makes it trivially simple to check, change, or modify, the setting on EVERY site by any authorized user. Many of my clients would be comfortable, if necessary, administrating this option through the configuration dialog. NONE of my clients would be comfortable/capable using settings.php.

PLEASE reinstate this useful function!

Thank you.

DeNelo’s picture

#24: Amen to that.

quicksketch’s picture

Status: Fixed » Active

Hi guys, thanks for weighing in again here. The point you make about settings.php being outside the realm of normal site builders is spot-on. I wouldn't expect a typical site builder to be able to work within settings.php to find such an option, especially in this situation where the feature is essentially hidden and undocumented. It's not even a feature of the module, rather this ability to set $conf variables directly is simply Drupal-wide functionality that you can use to set any variable value manually.

But with all that said, this feature has been requested by 3 users in this issue, out of nearly fifty thousand sites that use this module. Of course there are others who aren't represented here, but it's hard to determine if this is really a majority use-case or not. I was making the suggestion of modifying $conf for the exceptional circumstance, for which I think this may be the case.

I'm not really very keen on restoring this functionality, since I don't think it's common enough. But even if we do restore it, it needs to be updated so that it's written in a way that doesn't break existing sites (as it did in 1.16).

Mel55113’s picture

It's not clear to me how there was a problem with 1.16. I didn't experience the problem. Even if there was a problem, as reported, the fix was simple enough that it could be simply stated as a comment in implementing a newer version, e.g., check your settings after upgrading.

Even though only 3 users have requested this feature saying implying that only 3 users would use the feature ignores the others who undoubtedly didn't make a request because of the efforts of those three users. Also, less experienced webmasters and Drupal site builders may not even know that the feature provided by using a "fixed" target (instead of _blank) exists. It's highly likely that many more users would use the facility if it does exist than would request it in the first place or comment in this thread. Personally I hacked the module many, many times, in Drupal 6 and now in Drupal 7, before investigating a better solution.

So, I say again:

PLEASE reinstate this useful function!

Thank you.

elachlan’s picture

If you can supply a patch to re-implement the functionality without breaking existing sites then we would look at it further.

elachlan’s picture

Status: Active » Postponed