簡體   English   中英

彈出窗口打開鏈接並自行關閉

[英]PopUp to open a link and close itself

我設置了一個彈出窗口,為訪問者提供兩個鏈接的選擇。 如果單擊其中一個鏈接,我希望(1)彈出窗口自行關閉,(2)所選鏈接在新的 window 中打開。 What occurs now when one of the two offered links is chosen is (1) the popup closes itself and (2) an empty new window opens. 如何讓選定的鏈接顯示在新的 window 中? 謝謝你。

這是我寫的代碼:

在主窗口的 HEAD 中:

    function OpenQuick() 
    {
    var windowcontents = "https://myurl.com/quicklink.html";
    var win =window.open(windowcontents,"remote",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=450,height=425');
win.creator=self;
myWindow.focus();
}

在主體 window 的主體中:

    <a href="javascript:OpenQuick();"><img src="https://www.myurl.com/images/link.gif"></a>

在彈出窗口中:

    <a href="choiceone.html" target="_blank" onclick="self.close();">First Choice</a>
    <a href="choicetwo.html" target="_blank" onclick="self.close();">Second Choice</a>    

萬一這可能有幫助。 我不建議對 OpenQuick() 進行任何更改:

function OpenQuick() {
  var windowcontents = "https://myurl.com/quicklink.html";
  var win=window.open( windowcontents, "remote", "(whatever)");
  win.creator=self;
  myWindow.focus();
}
<a href="#" onclick="OpenQuick();"><img src="(someimage)"></a>

在新/彈出窗口中 -

    <a href="choiceone.html" target="anyname" onclick="newRoutine();">Choice1</a>
    <a href="choicetwo.html" target="anyname" onclick="newRoutine();">Choice2</a> 

在該彈出窗口中使用 javascript 定義 newRoutine -

function newRoutine () {
  setTimeout( function () { self.close(); }, 1000); // 1000 is in ms = 1s
}

這個想法是在嘗試關閉之前給彈出窗口一些時間。

Yishmeray,你寫道,“如果這可能有幫助”,它不僅有幫助。 您的解決方案回答了我的問題並解決了我的問題,我敦促任何有類似問題的人嘗試根據他們的情況調整 Yishmeray 的建議,這很簡單,很容易理解。 它有效! 伊什梅雷,謝謝。

暫無
暫無

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

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