簡體   English   中英

javascript 彈出菜單和重定向 url

[英]javascript popup menu and redirect url

我用的是 Tinybox http://sandbox.scriptiny.com/tinybox2/

打開彈出 web 頁面。 我希望當我單擊 web 頁面上的鏈接時,彈出 web 頁面將關閉並自動重定向到鏈接 url 我單擊

我的 javascript 代碼和 html 代碼

<script type="text/javascript" src="tinybox.js"></script>
<script type="text/javascript">

function openJS(){}
function closeJS(){}

function closeAndGotoURL{ 
TINY.box.hide();
opener.location.href='http://www.google.com';
}


 <a href="#"  onclick="TINY.box.show({iframe:'webpage2.html',boxid:'frameless',width:750,height:450,fixed:false,maskid:'bluemask',maskopacity:40,closejs:function(){closeJS()}})">Open page2</a>


//...below is on webpage2.html, it does not work

<a href="#" onclick="closeAndGotoURL()"> Click </a>

但這看起來不起作用

而不是opener.location.href ,使用parent.location.href 見下文:

function closeAndGotoURL {
    TINY.box.hide();
    parent.location.href='http://www.google.com';
}

您也可以使用top.location.href

function closeAndGotoURL {
    TINY.box.hide();
    top.location.href='http://www.google.com';
}

另一種選擇是使用純 HTML。 雖然它不會首先關閉彈出窗口,但它會將整個 window 重定向到您的 URL。 注意錨標記的target屬性。

<a href="http://www.google.com" target="_top">

注意1:為什么要先關閉彈出窗口? 如果您要重定向整個頁面,只需重定向 - 無需關閉彈出窗口。

注意 2:只有在 iframe 中加載的頁面與父 window 位於同一域中時,這才能正常工作(我假設這是因為您正在編寫彈出代碼)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM