我设置了一个弹出式窗口,让访问者可以选择两个链接。如果点击其中一个链接,我希望(1)弹出窗口自动关闭,(2)选择的链接在新窗口中打开。现在发生的情况是:(1)弹出窗口自动关闭,(2)打开一个空的新窗口。我如何才能让选择的链接显示在新窗口中?谢谢你。
这是我写的代码。
在主窗口的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();
}
在主窗口的主体中:
<a href="javascript:OpenQuick();"><img src="https://www.myurl.com/images/link.gif"></a>
在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>
如果这可能会有帮助。我不建议对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。 我呼吁有类似问题的人,可以尝试根据自己的情况调整Yishmeray的建议。它很简单,很容易理解,而且很有效! Yishmeray,谢谢你。