简体   繁体   中英

PopUp to open a link and close itself

I have set up a popup that offers a visitor the choice of two links. If either one of the links is clicked on, I would like for (1) the popup to close itself and (2) the selected link to open in a new 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. How can I get the selected link to display in the new window? Thank you.

Here is the code I have written:

In the main window's 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();
}

In the Body of the main window:

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

In the POPUP:

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

In case this might help. I don't propose any change to 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>

In new / popup -

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

With javascript definition of the newRoutine on that popup -

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

The idea being to give the popup a bit of time before trying the close.

Yishmeray, You wrote, "In case this might help", Not only did it help. your solution answered my question and solved my problem, I urge anyone who has a similar issue to try adapting Yishmeray's suggestion to their situation, It's simple, it's easy to understand. and it works! Yishmeray, thank you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM