简体   繁体   English

防止浏览器的后退按钮重新打开上一页的弹出窗口

[英]Prevent browser's back button from reopening pop up window on previous page

How would I prevent the browser from opening the pop up window that was displayed from the previous page when the user clicks the back button? 当用户单击后退按钮时,如何阻止浏览器打开上一页显示的弹出窗口?

I hope that made sense but I'll explain it in point form below: 我希望这是有道理的,但我会在下面的点形式解释它:

There are three pages: Page1, Page2, Page3 共有三页:Page1,Page2,Page3

  1. User loads Page1 and clicks a link to load Page2 in a new window using JavaScript (ie window.open(...)). 用户加载Page1并单击链接以使用JavaScript(即window.open(...))在新窗口中加载Page2。 The User can close Page2 anytime they wish-- but we'll assume the user does so before step 2. 用户可以随时关闭Page2--但我们会假设用户在第2步之前这样做。

  2. User now clicks a link on Page1 to load Page3. 用户现在单击Page1上的链接以加载Page3。

  3. User is now on Page3 and clicks the back button on their browser. 用户现在在Page3上并单击其浏览器上的后退按钮。

  4. Page1 is displayed in the browser but Page2 is displayed again in a pop up window. Page1显示在浏览器中,但Page2再次显示在弹出窗口中。

So, I'm wondering if there is a way to prevent Page2 from popping up again. 所以,我想知道是否有办法阻止Page2再次弹出。 I am using classic ASP as well, if it matters. 如果重要的话,我也使用经典的ASP。

If Page2 is opened as a result of clicking a link, how is it automatically being opened when the back button is clicked? 如果单击链接打开Page2,单击后退按钮时如何自动打开? Unless Page2 is opened automatically on the initial load of Page1, it shouldn't pop up due to the back button being pressed - pressing "Back" doesn't click a link on the previous page. 除非在Page1的初始加载时自动打开Page2,否则由于按下后退按钮不会弹出Page2 - 按“后退”不会单击上一页上的链接。 I suspect something else is going on in your page - can we see some code please? 我怀疑你的页面还有其他的东西 - 我们可以看到一些代码吗?

you can try creating a session variable on page2. 您可以尝试在第2页上创建会话变量。 and check if it exist upon opening of page1. 并在第1页打开时检查它是否存在。 or use a cookie. 或使用cookie。

EDIT: 编辑:

Function IsPostBack()
    IsPostBack = (Request.ServerVariables("REQUEST_METHOD") = "POST")
End Function

this will not detect a page refresh though.. 这不会检测到页面刷新..

The page was redirecting to itself and inserting the javascript code to pop up a new window based on the button pressed previously. 该页面重定向到自身并插入javascript代码以基于之前按下的按钮弹出一个新窗口。 I think it determined this via the post or get methods. 我认为这是通过post或get方法确定的。 I forget now. 我现在忘记了。

As such, when the user presses the back button, they will reload the page with the embedded javascript code and not the original page. 因此,当用户按下后退按钮时,他们将使用嵌入的javascript代码而不是原始页面重新加载页面。

We've since left classic ASP behind so I can't really test any suggestions but appreciate the help. 我们已经离开了经典的ASP,所以我无法真正测试任何建议,但感谢帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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