Calling a page via a link with a target attribute

Filed under: JavaScript

comments (0) Views: 4,552

Today over at House of Fusion Claude Schneegans asked:

Suppose I have a page like myPage.cfm. Is it possible in this page to detect if it was called from a link having a TARGET="..." attribute?

I decided to throw something together to determine if this was indeed possible. Turns out it is, and here's how I accomplished it. I first whipped up a plain HTML page with two links on it, like so:


<a href="child.html" target="_blank">Open child.html with target="_blank"</a>
<br /><br />
<a href="child.html">Open child.html as normal window</a>

I then wrote a companion page which used JavaScript to try and determine the "parent"


var opener = (parent.opener) ? parent.opener.location.href : 'an unknown window';
$('span').html(myParent);

Finally, I used jQuery to write the result of the test to a span tag on the child page. Admittedly this has limited use, but it's a nice means of determining if a target attribute was used to open the window, which essentially gives you access to the parent page with JavaScript if that page is still open.

View the demo.

Amazon logo

If this article was interesting, or helpful, or even wrong, please consider leaving a comment, or buying something from my wishlist. It's appreciated!

comments powered by Disqus
coach outlet online jordan 13 grey toe beats by dre cyber monday michael kors black friday beats by dre cyber monday jordan 6 black infrared north face cyber monday michael kors cyber monday north face black friday coach outlet black infrared 23 13s north face cyber monday jordan 6 black infrared north face black friday coach cyber monday jordan 11 legend blue north face cyber monday black infrared 6s lebron 12 north face black friday jordan 11 legend blue louis vuitton outlet jordan 13 grey toe grey toe 13s beats by dre black friday coach black friday jordan 13 grey toe coach cyber monday uggs black friday jordan 13 black infrared 23 uggs cyber monday barons 13s uggs black friday beats by dre cyber monday black infrared 6s jordan 13 bred jordan 13 black infrared 23 north face black friday black infrared 6s jordan 11 legend blue michael kors black friday jordan 13 grey toe coach black friday michael kors black friday michael kors cyber monday beats by dre cyber Monday north face cyber monday coach black friday michael kors cyber monday beats by dre cyber Monday north face black friday beats by dre black friday lululemon black friday uggs black friday jordan 13 bred coach cyber monday beats by dre black friday uggs black friday coach black friday black infrared 6s