Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Link To New Tab
- // @namespace http://*
- // @description Opens links external to the current site in a new tab
- // @include http*
- // ==/UserScript==
- // Ignore links with relative URLs
- // and links to the current site
- function linkToNewTab() {
- var anchors = document.getElementsByTagName("a");
- for(var i = 0; i < anchors.length; i++) {
- if(anchors[i].href.indexOf("http") == 0
- && anchors[i].href.indexOf(window.location.host) == -1) {
- anchors[i].target = "_blank";
- }
- }
- }
- window.addEventListener("load",function(){linkToNewTab()},false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement