Version Description
Fixed: Credits to Tom Köhler (Charset) Fixed: Links
Download this release
Release Info
| Developer | kezze |
| Plugin | |
| Version | 1.0 |
| Comparing to | |
| See all releases | |
Version 1.0
- open-external-links-in-a-new-window.php +55 -0
- readme.txt +41 -0
open-external-links-in-a-new-window.php
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
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.0
|
| 8 |
+
Author URI: http://kezze.dk
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
add_action('wp_head', 'external_links_in_new_windows');
|
| 12 |
+
|
| 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) {
|
| 22 |
+
document.links = document.getElementsByTagName('a');
|
| 23 |
+
}
|
| 24 |
+
|
| 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].setAttribute('target', '');
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
function addLoadEvent2(func)
|
| 38 |
+
{
|
| 39 |
+
var oldonload = window.onload;
|
| 40 |
+
if (typeof window.onload != 'function'){
|
| 41 |
+
window.onload = func;
|
| 42 |
+
} else {
|
| 43 |
+
window.onload = function(){
|
| 44 |
+
oldonload();
|
| 45 |
+
func();
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
addLoadEvent2(makeNewWindows);
|
| 51 |
+
";
|
| 52 |
+
|
| 53 |
+
echo "//]]></script>\n\n";
|
| 54 |
+
}
|
| 55 |
+
?>
|
readme.txt
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
=== Open external links in a new window ===
|
| 2 |
+
Contributors: kezze, Zap
|
| 3 |
+
Donate link: https://www.paypal.com/xclick/business=paypal%40kezze.dk&item_name=Donation&no_note=1&tax=0¤cy_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
|
| 8 |
+
|
| 9 |
+
Opens all external links in a new window. XHTML Strict compliant and search engine optimized (SEO).
|
| 10 |
+
|
| 11 |
+
== Description ==
|
| 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.
|
| 19 |
+
|
| 20 |
+
Based on the source of [Zap_NewWindow](http://www.zappelfillip.de/2005-12-05/zap_newwindow/ "Another Wordpress plugin") by [Tom Köhler](http://www.zappelfillip.de/ "His website is mostly in German"). Thanks a lot!
|
| 21 |
+
|
| 22 |
+
== Installation ==
|
| 23 |
+
1. Copy the plugin to /wp-content/plugins/
|
| 24 |
+
1. Activate this plugin.
|
| 25 |
+
|
| 26 |
+
== Changelog ==
|
| 27 |
+
|
| 28 |
+
= 1.0 =
|
| 29 |
+
Fixed: Credits to Tom Köhler (Charset)
|
| 30 |
+
Fixed: Links
|
| 31 |
+
|
| 32 |
+
= 0.9 =
|
| 33 |
+
Initial release
|
| 34 |
+
|
| 35 |
+
== Upgrade Notice ==
|
| 36 |
+
|
| 37 |
+
= 1.0 =
|
| 38 |
+
Ready for production.
|
| 39 |
+
|
| 40 |
+
= 0.9 =
|
| 41 |
+
Initial release
|
