2017-01-19 59 views
0

有誰知道如何實現下面的JavaScript過程? 我使用colorbox來顯示iframe。想關閉它後重定向到colorbox iframe中的另一個頁面

  1. 我設置了colorbox iframe上的橫幅鏈接。
  2. 我希望這個iframe在點擊橫幅時關閉,之後我希望父窗口重定向到另一個頁面。

以下2碼是什麼I`ve嘗試:

1 
<div> 
<a href='#' onclick='parent.$.colorbox.close();linkto();'> 
<img src="../images/test.png" alt=「#」 > 
</a> 
<script> 
function linkto() { 
location.href = "https://www.test.com"; 
} 
</script> 
</div> 

2 
<div> 
<a href='#' onclick='parent.$.colorbox.close(); window.location.href ='https://www.test.com;'> 
<img src="../images/test.png" alt=「#」 > 
</a> 
</div> 

回答

0

可以使用window.top.location.href to target the top most window element and redirect to the specified page. This can be done from within an iframe`。

HTML:

<a href='#' onclick='parent.$.colorbox.close(); linkTo();"> 

JS:

function linkTo() { 
    window.top.location.href = "https://www.test.com"; 
} 
+0

謝謝你的偉大的答案! – yusaw

+0

我會盡快嘗試:) – yusaw

+0

謝謝你的幫助亞歷山大,我已經證實它進展順利:) – yusaw

相關問題