我有两个(或更多)链接。例如:http://google.com和http://yahoo.com。
当我单击一个链接时,如何使它们都打开?
例如,一个名为“单击此处”的链接,单击该链接时,将打开两个不同的空白窗口。
发布于 2011-08-15 12:42:58
HTML:
<a href="#" class="yourlink">Click Here</a>联署材料:
$('a.yourlink').click(function(e) {
e.preventDefault();
window.open('http://yoururl1.com');
window.open('http://yoururl2.com');
});window.open也可以接受额外的参数。在这里看到他们:http://www.javascript-coder.com/window-popup/javascript-window-open.phtml
您还应该知道,window.open有时会被弹出拦截器和/或广告过滤器阻塞。
除了下面的Paul :此方法还对启用的JavaScript设置了依赖项。这不是一个好主意,但有时是必要的。
发布于 2013-05-31 03:51:23
我这么做的方式很简单:
<a href="http://virtual-doctor.net" onclick="window.open('http://runningrss.com');
return true;">multiopen</a>它将在新窗口中打开朗宁,在同一个窗口中打开虚拟医生。
发布于 2011-08-15 12:55:06
您可能希望安排您的HTML,以便用户仍然可以打开所有的链接,即使没有启用JavaScript。(我们称之为渐进式增强。)如果是这样的话,这样的事情可能会很好:
HTML
<ul class="yourlinks">
<li><a href="http://www.google.com/"></li>
<li><a href="http://www.yahoo.com/"></li>
</ul>jQuery
$(function() { // On DOM content ready...
var urls = [];
$('.yourlinks a').each(function() {
urls.push(this.href); // Store the URLs from the links...
});
var multilink = $('<a href="#">Click here</a>'); // Create a new link...
multilink.click(function() {
for (var i in urls) {
window.open(urls[i]); // ...that opens each stored link in its own window when clicked...
}
});
$('.yourlinks').replaceWith(multilink); // ...and replace the original HTML links with the new link.
});这段代码假设您只想使用一个“多链接”,比如每个页面。(我也没有测试过它,所以它可能充满了错误。)
https://stackoverflow.com/questions/7064998
复制相似问题