Open external links in a new window - Version 1.0.1

Version Description

Fixed: Removes target attribute from links instead of setting the attribute to null. (Thanks to crashnet)

Download this release

Release Info

Developer kezze
Plugin Icon 128x128 Open external links in a new window
Version 1.0.1
Comparing to
See all releases

Code changes from version 1.1.1 to 1.0.1

open-external-links-in-a-new-window.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Open external links in a new window
4
  Plugin URI: http://wordpress.org/extend/plugins/open-external-links-in-a-new-window/
5
  Description: Opens all external links in a new window. XHTML Strict compliant and search engine optimized (SEO).
6
  Author: Kristian Risager Larsen
7
- Version: 1.1.1
8
  Author URI: http://kezze.dk
9
  */
10
 
@@ -13,9 +13,9 @@ add_action('wp_head', 'external_links_in_new_windows');
13
  function external_links_in_new_windows()
14
  {
15
  echo "\n\n<!-- External links open in a new window. Plugin by Kristian Risager Larsen, http://kezze.dk . Download it at http://wordpress.org/extend/plugins/open-external-links-in-a-new-window/ -->\n";
16
-
17
- $blogdomain = parse_url(get_option('home'));
18
  echo "<script type=\"text/javascript\">//<![CDATA[";
 
19
  echo "
20
  function makeNewWindows() {
21
  if (!document.links) {
@@ -25,8 +25,9 @@ function external_links_in_new_windows()
25
  for (var t=0; t<document.links.length; t++) {
26
  var all_links = document.links[t];
27
  if (all_links.href.search(/^http/) != -1) { // Catches both http and https
28
- if (all_links.href.search('/".$blogdomain['host']."/') == -1 && document.links[t].hasAttribute('onClick') == false) {
29
- document.links[t].setAttribute('onClick', 'javascript:window.open(\\''+all_links.href+'\\'); return false;');
 
30
  document.links[t].removeAttribute('target');
31
  }
32
  }
@@ -51,4 +52,4 @@ function external_links_in_new_windows()
51
 
52
  echo "//]]></script>\n\n";
53
  }
54
- ?>
4
  Plugin URI: http://wordpress.org/extend/plugins/open-external-links-in-a-new-window/
5
  Description: Opens all external links in a new window. XHTML Strict compliant and search engine optimized (SEO).
6
  Author: Kristian Risager Larsen
7
+ Version: 1.0.1
8
  Author URI: http://kezze.dk
9
  */
10
 
13
  function external_links_in_new_windows()
14
  {
15
  echo "\n\n<!-- External links open in a new window. Plugin by Kristian Risager Larsen, http://kezze.dk . Download it at http://wordpress.org/extend/plugins/open-external-links-in-a-new-window/ -->\n";
16
+
 
17
  echo "<script type=\"text/javascript\">//<![CDATA[";
18
+ $blogdomain = parse_url(get_settings('home'));
19
  echo "
20
  function makeNewWindows() {
21
  if (!document.links) {
25
  for (var t=0; t<document.links.length; t++) {
26
  var all_links = document.links[t];
27
  if (all_links.href.search(/^http/) != -1) { // Catches both http and https
28
+ if (all_links.href.search('/".$blogdomain['host']."/') == -1) {
29
+ // all_links.setAttribute('target', '_blank');
30
+ document.links[t].setAttribute('href', 'javascript:window.open(\\''+all_links.href+'\\'); void(0);');
31
  document.links[t].removeAttribute('target');
32
  }
33
  }
52
 
53
  echo "//]]></script>\n\n";
54
  }
55
+ ?>
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: kezze, Zap
3
  Donate link: https://www.paypal.com/xclick/business=paypal%40kezze.dk&item_name=Donation&no_note=1&tax=0&currency_code=EUR
4
  Tags: links, external links, target blank, target new, window.open, new window, blank window, new tab, blank tab, tabs, SEO, xhtml strict, javascript
5
  Requires at least: 2.0
6
- Tested up to: 3.1
7
- Stable tag: 1.1.1
8
 
9
  Opens all external links in a new window. XHTML Strict compliant and search engine optimized (SEO).
10
 
@@ -12,7 +12,7 @@ Opens all external links in a new window. XHTML Strict compliant and search engi
12
  Opens all external links (starting with `http://` or `https://`) in a separate browser window.
13
  The plugin produces XHTML Strict compliant code and is also search engine optimized (SEO).
14
 
15
- This is done using JavaScript's `window.open()`-function.
16
 
17
  Most other plugins perform a hack by altering the `target` parameter (i.e. `<a href="http://somewhere.example" target="_blank">`). That method is not XHTML Strict compliant.
18
  This plugin handles the links client-side, which lets search engines follow the links properly. Also, if a browser does not support JavaScript, the plugin is simply inactive, and does not result in any errors.
@@ -25,14 +25,8 @@ Based on the source of [Zap_NewWindow](http://www.zappelfillip.de/2005-12-05/zap
25
 
26
  == Changelog ==
27
 
28
- = 1.1.1 =
29
- Fixed: Resolved deprecation warning (Thanks to [boo1865](http://wordpress.org/support/topic/plugin-open-external-links-in-a-new-window-doesnt-work?replies=2#post-2152292))
30
-
31
- = 1.1.0 =
32
- Changed: Better practice for opening links. The plugin now uses the onClick-attribute instead of writing JavaScript directly into the href-attribute. This enables users to right-click the link and open in a new window/tab, save the target etc.
33
-
34
  = 1.0.1 =
35
- Fixed: Removes target attribute from links instead of setting the attribute to null. (Thanks to [crashnet](http://wordpress.org/support/topic/plugin-open-external-links-in-a-new-window-target-attribute-left-empty?replies=2#post-1813522))
36
 
37
  = 1.0 =
38
  Fixed: Credits to Tom K&ouml;hler (Charset)
@@ -43,12 +37,6 @@ Initial release
43
 
44
  == Upgrade Notice ==
45
 
46
- = 1.1.1 =
47
- Fixed: Resolved deprecation warning.
48
-
49
- = 1.1.0 =
50
- Better practice for opening links. Please upgrade.
51
-
52
  = 1.0.1 =
53
  Minor bugfix.
54
 
@@ -56,4 +44,4 @@ Minor bugfix.
56
  Ready for production.
57
 
58
  = 0.9 =
59
- Initial release
3
  Donate link: https://www.paypal.com/xclick/business=paypal%40kezze.dk&item_name=Donation&no_note=1&tax=0&currency_code=EUR
4
  Tags: links, external links, target blank, target new, window.open, new window, blank window, new tab, blank tab, tabs, SEO, xhtml strict, javascript
5
  Requires at least: 2.0
6
+ Tested up to: 3.0
7
+ Stable tag: 1.0.1
8
 
9
  Opens all external links in a new window. XHTML Strict compliant and search engine optimized (SEO).
10
 
12
  Opens all external links (starting with `http://` or `https://`) in a separate browser window.
13
  The plugin produces XHTML Strict compliant code and is also search engine optimized (SEO).
14
 
15
+ This is done using the `javascript:window.open()`-function.
16
 
17
  Most other plugins perform a hack by altering the `target` parameter (i.e. `<a href="http://somewhere.example" target="_blank">`). That method is not XHTML Strict compliant.
18
  This plugin handles the links client-side, which lets search engines follow the links properly. Also, if a browser does not support JavaScript, the plugin is simply inactive, and does not result in any errors.
25
 
26
  == Changelog ==
27
 
 
 
 
 
 
 
28
  = 1.0.1 =
29
+ Fixed: Removes target attribute from links instead of setting the attribute to null. (Thanks to [crashnet](http://wordpress.org/support/topic/plugin-open-external-links-in-a-new-window-target-attribute-left-empty?replies=2))
30
 
31
  = 1.0 =
32
  Fixed: Credits to Tom K&ouml;hler (Charset)
37
 
38
  == Upgrade Notice ==
39
 
 
 
 
 
 
 
40
  = 1.0.1 =
41
  Minor bugfix.
42
 
44
  Ready for production.
45
 
46
  = 0.9 =
47
+ Initial release