繁体   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