Open external link in new tab

This script will open any external link in new tab. Support dynamic content

目前为 2015-05-14 提交的版本。查看 最新版本

// ==UserScript==
// @name        Open external link in new tab
// @version     0.1.3
// @namespace   eight04.blogspot.com
// @description This script will open any external link in new tab. Support dynamic content
// @include     http*
// @grant		none
// ==/UserScript==

"use strict";

function getAnchor(element) {
	while (element && element.nodeName != "A") {
		element = element.parentNode;
	}
	return element;
}

document.addEventListener("click", function(e){
	var anchor = getAnchor(e.target);
	if (!anchor || anchor.target || anchor.protocol == "javascript:" || e.isTrusted === false || !anchor.offsetParent || (e.isTrusted == null && !e.detail)) {
		return;
	}
	if (anchor.hostname != location.hostname) {
		anchor.target = "_blank";
	}
});

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址