You need to be logged in to post in the forums. If you do not have an account, please sign up first.
Link opened in new tab for 'external' links by default
OK; I admit I was a Tab Mix Plus addicted when I used Firefox.. but this feature is very incredibly useful, I think:I'd like if links were opened in new tabs when they bring to a link of a domain different from the current one. I hope I explained it well
Try something like this.
for (var i=0; var x=document.links[i]; i++) {
if (x.hostname != location.hostname) {
x.target = '_blank';
}
}
The DnD Sanctuary — a safety net for My Opera's demise.
Correct. Note that I haven't tested the code, but it should be something along these lines.
document.addEventListener(
'DOMContentLoaded',
function()
{
for (var i=0; var x=document.links[i]; i++) {
if (x.hostname != location.hostname) {
x.target = '_blank';
}
}
},
false
);
The DnD Sanctuary — a safety net for My Opera's demise.
Thank you very much, Frenzie. I wouldn't harass you, but I tried with this JS and it didn't work 
External Links Test.user.js

External Links Test.user.js
If you're doing that you should use what I originally posted.
i.e. either a file named something like external-links.user.js with
or a file named something like external-links.js with the code I posted above.
Or you could use what you put in that file, but then you'll need to replace DOMContentLoaded with load.
And harassing would be sending me PMs excessively or something, lol.
i.e. either a file named something like external-links.user.js with
// ==UserScript==
// @name External Links
// ==/UserScript==
for (var i=0; var x=document.links[i]; i++) {
if (x.hostname != location.hostname) {
x.target = '_blank';
}
}
or a file named something like external-links.js with the code I posted above.
Or you could use what you put in that file, but then you'll need to replace DOMContentLoaded with load.
And harassing would be sending me PMs excessively or something, lol.
The DnD Sanctuary — a safety net for My Opera's demise.
I messed a little thing up in the syntax earlier because I didn't test it. This should work.
external-links-blank.user.js
external-links-blank.user.js
The DnD Sanctuary — a safety net for My Opera's demise.
Really? It works for me on, for example, my blog. Without the script links outside my blog (recognizable by the little blue arrow) open in the same window, whereas with the script they automatically open in a new tab.
The DnD Sanctuary — a safety net for My Opera's demise.
Google links to itself which then redirects you in most cases, so yeah, that wouldn't be detected by this script.
The DnD Sanctuary — a safety net for My Opera's demise.