admin管理员组

文章数量:1336293

I have an HTML page and have Four Links to go to Different pages on a new window.

For Example:

Link1, Link2, Link3 Link4

And I want Link 1 to pop-up in a new Window 1, Link2 to new Window 2 and so on...

So that Window 1 and its content from Link1 will stay when Link2 is clicked.

Currently, the problem is that the four links opens up in a new Window 1 covering up the first current content from Link1. What I want is to have four unique window every time a Link is clicked.

I don't know if there's a certain Javascript function to do this but what I have right now on those four link is just target="_blank" on an anchor tag. This happens in IE and Chrome and I would think also in FF and any other browsers.

Thanks in advance for the help.

I have an HTML page and have Four Links to go to Different pages on a new window.

For Example:

Link1, Link2, Link3 Link4

And I want Link 1 to pop-up in a new Window 1, Link2 to new Window 2 and so on...

So that Window 1 and its content from Link1 will stay when Link2 is clicked.

Currently, the problem is that the four links opens up in a new Window 1 covering up the first current content from Link1. What I want is to have four unique window every time a Link is clicked.

I don't know if there's a certain Javascript function to do this but what I have right now on those four link is just target="_blank" on an anchor tag. This happens in IE and Chrome and I would think also in FF and any other browsers.

Thanks in advance for the help.

Share Improve this question asked Aug 22, 2013 at 7:11 mark-in-motionmark-in-motion 2936 silver badges25 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 2

target="_blank" will open each link in a new window (it doesn't matter if the link is already opened);

If you want to focus the opened window, you can use modal windows (i.e. not tabs) as follows:

html:

<a href="http://google.">link 1</a><br/>
<a href="http://yahoo.">link 2</a><br/>
<a href="http://bing.">link 3</a><br/>
<a href="http://mamma.">link 4</a>

js:

$(document).ready(function() {
    $('a').click(function(e) {
        var id = $(this).data("windowid");
        if(id == null || id.closed) {
            id =  window.open($(this).attr("href"), '_blank', 'modal=yes');
        }
        id.focus();
        $(this).data("windowid", id);
        e.preventDefault();
        return false;
    });
});

http://jsfiddle/JeQyE/2/

Try

var links = document.getElementsByTagName("a");
for (var i = 0; i < links.length; i++) {
    var link = links[i];
    link.addEventListener("click", function (e) {
        e.preventDefault();
        window.open(this.href);
    });
}

use window.open javascript function as bellow,

window.open("your link")

target can also accept a name instead of "_blank" e.g. win1 win2 etc

see http://www.w3/html/wg/drafts/html/master/browsers.html#browsing-context-names

本文标签: javascriptForce different links to open in a new Popup window every timeStack Overflow