2012-12-27 99 views
1

我已經使用了鏈接,進入到外部網站的onclick功能得到:附加鏈接到一個新的鏈接

<a href="http://outsidelink.net" target="_blank" onclick="return confirm('You will now be transfered to a third party website');">External Link</a> 

但因爲我已經創造了一個「收藏夾」像使用jQuery,告知用戶該版本他們正在去另一個第三方網站。我不想每次手動將每個鏈接複製到新的燈箱中。我寧願從頁面上的鏈接複製href,並將其添加到我的lightbox中的「繼續」按鈕。

我怎麼會拿一個鏈接是這樣的:

<a class="outsidelink" href="http://outsidelink.net">External Link</a> 

,並將其添加到我的收藏在那裏我有「CopiedLink」:

<div id="container"> 
<div id="textbox"> 
<a id="nothanks" href="#">Close</a> 
<p>You are about to leave the site and go to a third party website.</p> 
<a id="newlinkontheblock" href="CopiedLink" target="_blank">Continue</a> 
</div> 
</div> 

我已經創建了。點擊函數創建燈箱,我只是不知道如何從頁面中獲取鏈接並將其插入到新創建的燈箱中。有任何想法嗎?

回答

3

像這樣的事情應該去做

$('a.outsidelink').click(function(e){ 
    // cancel default action of link so that it is not followed 
    e.preventDefault(); 

    // open light box here 


    // then 
    $('#newlinkontheblock').attr('href', this.href); 
}); 
+0

非常簡單的執行 – user1161032