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 badges4 Answers
Reset to default 2target="_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
版权声明:本文标题:javascript - Force different links to open in a new Pop-up window every time - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742390294a2465854.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论