简体   繁体   English

不要使用后退按钮弹出弹出窗口

[英]Do not let pop up to come up by using back button

I used pop up in my site.The problem is, when i open a pop up and go to the other page and then go back to previous page, a pop up will refresh and open again!! 我在网站上使用了弹出窗口。问题是,当我打开一个弹出窗口并转到另一页然后返回上一页时,弹出窗口将刷新并再次打开! without any pressed! 没有任何按下! How can i fix it? 我该如何解决? I want that this pop up wont come up again by coming back to that page. 我希望此弹出窗口不会通过返回该页面再次出现。

here is my Pop up code: 这是我的弹出代码:

.......
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.3/jquery-ui.min.js" ></script>  
<script type='text/javascript' src='jquery-1.2.3.min.js'></script>
<script type='text/javascript' src='menu.js'></script>

  <script type="text/javascript">
      function pop_up(url) {
          newwindow = window.open(url, 'name', 'height=517,width=885,scrollbars=yes,toolbar=no,menubar=no,resizable=yes,location=no,directories=no,status=no,titlebar=no,left=400,top=120');
          if (window.focus) { newwindow.focus() }
          return false;
      }
    </script>


<link href="style.css" rel="stylesheet" type="text/css" />

    <style type="text/css">
        .style2
        {
.......

and behind code: 和背后的代码:

Page.ClientScript.RegisterStartupScript(GetType(), "popup", "pop_up('" + "PopUpEmailing.aspx" + "');", true);

One solution would be to use the window.name property. 一种解决方案是使用window.name属性。 I know this solution can lead to conflicts if another library also tries to use this. 我知道,如果另一个库也尝试使用此解决方案,则可能导致冲突。 But I prefer this more then using a cookie. 但我更喜欢使用cookie。 (You could also think over using local storage) (您也可以考虑使用本地存储)

function displayPopUp() {
    if( window.name != "popup-displayed" ) {
        window.name = "popup-displayed";
        ... popup code ...
    }
}

Instead of using Page.ClientScript.RegisterStartupScript try the following. 代替使用Page.ClientScript.RegisterStartupScript尝试以下操作。

<asp:Button runat="server" ID="btnTest" Text="My Button" OnClientClick="pop_up('" + "PopUpEmailing.aspx" + "')"><asp:Button>

The above will create a button and when the button will be click a client side event will be called and it will run your pop_up javascript code. 上面将创建一个按钮,当单击按钮时,将调用一个客户端事件,它将运行您的pop_up javascript代码。

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

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