Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do Google opening links in a new window without target attribute?

Tags:

hyperlink

i wonder how google manages to open external links in a new window/tab without defining target="_blank".

For example in google plus, all external links open in a new window. I think its some Javascript voodoo but the .js code is obfuscated so i cant really look into.

edit: oh and followup question: why?

like image 329
Michele Avatar asked Jan 27 '26 18:01

Michele


1 Answers

Using a framework makes this easy. Just have JavaScript look for links marked rel="external", or another identifier that shows them to be an external link, and dynamically add target="blank". Here's an example using Prototype:

$$('a[rel="external"]').each(function(a) {
  a.setAttribute('target', '_blank');
};
like image 109
John Conde Avatar answered Jan 29 '26 11:01

John Conde



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!