Prevent redirecting an external MY page (parent) page

Use the latest version of Chrome on Mac OS 10.7.

I assume this is some kind of smart javascript that allows people on this web page:

http://www.chairworks.com/

... close my (parent) page by opening the first page (chairworks.com). I did not open them using javascript, but with the <a> tag with the target="_blank" attribute.

If javascript is disabled, the behavior will stop.

 <a href="http://www.chairworks.com" target="_blank">www.chairworks.com</a> 

I would expect the page on chairworks.com/ to simply open in a different tab / window ... but I found that as soon as a new browser tab opens, it closes and then my page (parent / window tab) redirects to the chairworks page .com.

Kinda rude.

Can someone tell me which code allows them to do this? And how can I prevent this? (Assuming I want the link to behave as expected, for example, on my demo page.)

+7
source share
3 answers

This is the script they use:

 setTimeout('redirect_page()',0); function redirect_page(){if (window.opener) { window.opener.location.href = '/home.html'; window.close(); } else { location.href = '/home.html'; }} 

How to get around this (just an idea):
Create your own blank page, and its source will be: blank. When it loads (or after a timeout), you can write code in this window, which will then open a link for violation. Then the abusive link simply closes your buffer page. F * ck 'm !! Power to the user!

Edit: it looks like you can also name your home.html page hehe, but this is not such a workable solution.

Final Edit: EASY LOGIC ...
<a href="http://www.chairworks.com/home.html" target="_blank">www.chairworks.com</a>
works for everyone, no javascript required.
See this working jsfiddle example .

+2
source

I believe the right thing is to set the appropriate link type attribute so that the browser does not provide the target window and opener .

 <a href="https://untrusted-site.org" target="_blank" rel="noreferrer noopener">Link</a> 

You can learn more about link types here: https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types

+5
source

As @GitaarLAB explained, the target site uses the window.opener property to access your page. Using some Javascript on your own and about:blank page in the middle, you can reduce access to your page. It would be like this:

  <a href="http://www.chairworks.com/" target="_blank" onclick="var w = window.open('about:blank'); w.opener = null; w.open('http://www.chairworks.com/'); return false;">http://www.chairworks.com/</a> 

Some notes:

  • I leave the href property for users without JS enabled (guess which target site will have no JS!), Nor web crawlers like search engines (only those who don't care about JS stuff, though)
  • Before redirecting to the target site, you trim the backlink by resetting the window.opener attribute of the new window.
  • And after opening the target website, there is return false; to prevent the browser from using the usual href and target attributes.
+1
source

All Articles