簡體   English   中英

不要使用后退按鈕彈出彈出窗口

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

我在網站上使用了彈出窗口。問題是,當我打開一個彈出窗口並轉到另一頁然后返回上一頁時,彈出窗口將刷新並再次打開! 沒有任何按下! 我該如何解決? 我希望此彈出窗口不會通過返回該頁面再次出現。

這是我的彈出代碼:

.......
  <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
        {
.......

和背后的代碼:

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

一種解決方案是使用window.name屬性。 我知道,如果另一個庫也嘗試使用此解決方案,則可能導致沖突。 但我更喜歡使用cookie。 (您也可以考慮使用本地存儲)

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

代替使用Page.ClientScript.RegisterStartupScript嘗試以下操作。

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

上面將創建一個按鈕,當單擊按鈕時,將調用一個客戶端事件,它將運行您的pop_up javascript代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM