问题描述
我有两个(或更多)链接。例如:和。
当我点击单个图片时,如何让它们都 打开链接?
例如,一个标题为点击这里的链接,点击后会打开两个不同的空白窗口。
HTML:
< a href =#class = yourlink>点击此处< / a>
JS:
$('a.yourlink')。click(function(e){
e.preventDefault();
window.open('http://yoururl1.com');
window.open('http://yoururl2.com');
});
window.open
也可以使用其他参数。在这里看到它们:
您还应该知道window.open有时会被弹出式窗口拦截器和/或ad-过滤器。
来自Paul的添加如下:这种方法也会启用对JavaScript的依赖。通常不是一个好主意,但有时是必要的。
I have two (or more) links. For example: http://google.com and http://yahoo.com.
How can I make them both open when I click on a single link?
For example, a link entitled "click here" which, when clicked, will open two different blank windows.
HTML:
<a href="#" class="yourlink">Click Here</a>
JS:
$('a.yourlink').click(function(e) {
e.preventDefault();
window.open('http://yoururl1.com');
window.open('http://yoururl2.com');
});
window.open
also can take additional parameters. See them here: http://www.javascript-coder.com/window-popup/javascript-window-open.phtml
You should also know that window.open is sometimes blocked by popup blockers and/or ad-filters.
Addition from Paul below: This approach also places a dependency on JavaScript being enabled. Not typically a good idea, but sometimes necessary.
这篇关于点击时如何创建链接打开多个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!