是否可以使用“confirmit”在同一窗口中打开新网址?

发布于 2024-09-02 00:29:35 字数 649 浏览 1 评论 0原文

我正在使用一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江心雾 2024-09-09 00:29:35

您可以设置当前窗口的位置,而不是打开一个新窗口:

<script type="text/javascript">

function confirmit()  { 
  if (window.confirm("My message")) {
    window.location.href = 'http://MyDestinationURL';
  } else {
    window.close();
  }
}

window.onunload = confirmit;

</script>

我不确定您是否真的想要尝试关闭当前窗口的 else 情况。如果您只想在否定响应时留在当前页面,请删除 else 部分。

Instead of opening a new window you can set the location of the current window:

<script type="text/javascript">

function confirmit()  { 
  if (window.confirm("My message")) {
    window.location.href = 'http://MyDestinationURL';
  } else {
    window.close();
  }
}

window.onunload = confirmit;

</script>

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 the else part.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文