如何创建双链接?

时间:2013-02-05 14:25:37

标签: html

如果用户点击了该链接,那么我想在新标签页中打开一个页面,然后跳转到父网站上的#section。没有JS怎么可能?

这不起作用: html <a href="http://google.com" target="_blank"><a href="#section">link</a></a>

3 个答案:

答案 0 :(得分:2)

AFAIK,您必须使用JavaScript通过同一个锚点请求多个网址。

<a href="#section" id="doubleLink">Some Text</a>

使用JavaScript,您可以观察onclick事件以打开一个新窗口,如下所示:

document.getElementById("doubleLink").onclick = function() {
    window.open("http://www.someothersite.com/");
}

答案 1 :(得分:2)

只需将#section添加到地址即可。

<a href="http://target_site#section">

答案 2 :(得分:0)

我认为你需要使用javascript,但不是很多:

document.getElementById('myLinkId').addEventListener('click', function() {window.location = '#section'}, false);

编辑:据我所知,没有javascript就无法完成。没有打开新标签的双链接会发生什么?

我意识到你可能还需要它在旧的IE中工作。

var doubleLink = document.getElementById('myLinkId');

if (window.addEventListener) {
doubleLink.addEventListener('click', function() {window.location = '#section'}, false);
} else {
doubleLink.attachEvent('onclick', function() {window.location = '#section'});
}
相关问题