Can I use target and window.name?

Scenario

Open a new tab ( http://example.com/slave ). Log in to the console:

window.name = "example-slave"

Open a new tab ( http://example.com/master ). Add HTML:

<a href="http://example.com" target="example-slave">Click me!</a>

Expected effect

The added link should open example.com in the first tab (example-slave).

Current effect

The added link opens a new window, and then each additional click opens example.com in this window.

Question

This is normal? Is it possible to get the expected effect?

+4
source share
2 answers

See specification :

_blank , , , , , , .

, . , .

, target window.open().

+3

, , -, -, . , - - (, Facebook), - , , .

window.open, location.href :

HTML:

<a href="/?something" target="mytarget">Open a link in new window</a> 
<a href="/?anotherthing" target="mytarget">Open a link in opened window</a>

JS:

var targetlinks = document.querySelectorAll('[target="mytarget"]');

var opentarget = function(e){
    if( "mytarget" in window ){
         mytarget.location.href = e.target.href;   
    }
    else {
         window.mytarget = window.open( e.target.href, 'mytarget' );   
    }
    e.preventDefault();
};

[].slice.call( targetlinks ).forEach( function(link){
    link.addEventListener('click', opentarget );
});

( jsfiddle, probaly - , -).

0

All Articles