2013-02-05 88 views
1

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

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

回答

2

据我所知,你必须使用JavaScript通过相同的锚,请求多个URL。

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

使用JavaScript,你就可以观看了onclick事件打开一个新的窗口,就像这样:

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

我认为,由“父站点”,他指的是他自己的网站,而不是yoursite.com – spg

+0

我的意思是,我想在新标签页中打开,例如谷歌,并跳转到一个节在我的网站 – friction

+0

@friction AFAIK你必须使用JavaScript。 – railgun

2

只需添加#section的地址。

<a href="http://target_site#section"> 
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'}); 
}