是否可以使用“confirmit”在同一窗口中打开新网址?
我正在使用一个confirmit java脚本函数来重定向到一个带有肯定响应的新url。它并没有完全满足我的要求——也许我也无法得到我想要的东西。
这就是它的作用 - onunload 时,它会在新窗口中打开新的 url,并做出积极响应,该窗口可以在用户不知情的情况下被弹出窗口拦截器拦截,给人一种什么都没发生的印象。当它打开新 URL 时,它会在新窗口中打开,从而使桌面变得拥挤。它只是不是一个很好的解决方案。
我希望它做什么 - onunload 我希望它在同一窗口中打开新网址,并且不将其归类为要阻止的“弹出窗口”。我尝试切换到 onbeforeunload....没什么。
有一个简单的解决方案吗?
这是我当前的代码:
<script language=javascript>
function confirmit()
{
var closeit= confirm("My message");
if (closeit == true)
{window.open("http://MyDestinationURL");}
else
{window.close();} } window.onunload = confirmit
</script>
I'm using a the confirmit java script function to redirect to a new url with a positive response. It doesn't do exactly what I want - and maybe I can't have exactly what I want.
Here's what it does - onunload, with a positive response it opens the new url in a new window, which can be blocked by a pop-up blocker without the user even knowing, giving the impression that nothing happened. When it does open the new URL it opens in a new window making the desktop crowded. Its just not a great solution.
What I want it to do - onunload I'd like it to open the new url in the same window and have it not be classified as a "pop-up" to be blocked. I tried switching to onbeforeunload.... nuthin.
Is there a simple solution?
here's my current code:
<script language=javascript>
function confirmit()
{
var closeit= confirm("My message");
if (closeit == true)
{window.open("http://MyDestinationURL");}
else
{window.close();} } window.onunload = confirmit
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以设置当前窗口的位置,而不是打开一个新窗口:
我不确定您是否真的想要尝试关闭当前窗口的
else
情况。如果您只想在否定响应时留在当前页面,请删除else
部分。Instead of opening a new window you can set the location of the current window:
I am not sure if you actually want the
else
case where it tries to close the current window. If you just want to stay on the current page on a negative response, remove theelse
part.