5

I'm using the "filtered HTML" text format in the node body with the "convert URLs into links" option enabled. I would like to have all external links open in a new window. How can I do that?

0

3 Answers 3

7

The External Links module does exactly that:

External Links is a small module used to differentiate between internal and external links. Using jQuery, it will find all external links on a page and add an external icon indicating it will take you offsite or a mail icon for mailto: links.

Configuration options:

  • Apply icons to either mailto: or external links or both.
  • Configure external links to open in a new window.
  • A confirmation message when leaving the site.
  • Regular expression inclusion and exclusion of links considered external.
  • CSS selector inclusion and exclusion of elements for processing
5

If you don't want to use JavaScript for this, you need to implement theme_link(&variables) in your template.php file.

Test $variables['path'] for scheme declaration at the beginning. If there is none, leave it be. If there is some, add target to attributes:

$variables['options']['attributes']['target'] = '_blank';

Of course it bases on assumption that your HTML version supports target attribute, but this version is also theme-dependent, and most browsers will respect it even if technically it shouldn't be there.

1

You can use the Linkit module and add a "target" attribute at admin/config/content/linkit/manage/default/attributes/add

It has two options:

  • Selectlist with predefined targets.

Dialog with options

  • Simple checkbox to allow links to be opened in a new browser window or tab.

Dialog with checkbox

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.