Javascript判斷是否關閉,去除頁面中的所有的Script代碼 ,去除html中中的html元素

來源:互聯網
上載者:User

 1、使用Javascript方式

  在每一個頁面中加入一段Javascript代碼:

  function window.onbeforeunload()

  {

  if (event.clientX>document.body.clientWidth && event.clientY<0||event.altKey){

  window.open("logout.ASPx");

  }

  }

  由於onbeforeunload方法在瀏覽器關閉、重新整理、頁面調轉等情況下都會被執行,所以需要判斷是點擊了關閉按鈕或是按下Alt F4時才執行真正的關閉操作。

  然後在logout.aspx的Page_Load中寫和Session_End相同的方法,同時在logout.ASPx中加入事件:onload="Javascript:window.close()"

  但是這樣還是有問題,Javascript在不同的瀏覽器中可能有不同的行為,還有就是當通過檔案->關閉時沒有判斷到。

    常用到的WEB服務
    http://topic.csdn.net/u/20081217/13/5a9075fc-feb1-4cde-96ac-5f982f7a1b7b.html

 

  Wap   綁定資料  <mobile:Link ID="Link1" Runat="server" NavigateUrl='<% # "a.aspx?ID="+DataBinder.Eval(Container,"DataItem.No").ToString() %>'
Text="Link1"></mobile:Link>

   <mobile:Link ID="Link1" Runat="server" NavigateUrl='<% # "a.aspx?ID="+Eval("No").ToString() %>' > <%#Eval("Name") %></mobile:Link>

 

/// <summary>
        /// 去除頁面中的所有的Script代碼
        /// </summary>
        /// <param name="content"> </param>
        /// <returns> </returns>
        public static string FilterScript(string content)
        {
            string regexstr = @" <script([^ <script])*>.*(?= </script>) </script>";//使用邊界限制來擷取
            return Regex.Replace(content, regexstr, string.Empty, RegexOptions.IgnoreCase | RegexOptions.Singleline);
 
        }

/// <summary>
        /// 去除html中中的html元素
        /// </summary>
        /// <param name="content"> </param>
        /// <returns> </returns>
        public static string FilterHtml(string content)
        {
            string newstr = FilterScript(content);
            string regexstr = @" <[^>]*>";
            return Regex.Replace(newstr, regexstr, string.Empty, RegexOptions.IgnoreCase);
        }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.