posts - 0,comments - 8,trackbacks - 0

          在點擊瀏覽器關(guān)閉按鈕關(guān)閉瀏覽器的時候,有時不希望它直接關(guān)閉,希望彈出對話框提示客戶,這個時候就需要用到事件onbeforeunload,用法如下:
          <script language="javascript">
          <!--
          function opCheckUnload(){
          ? if(g_blnCheckUnload){
          ??? try{
          ????? window.event.returnValue = "if close the window,the auto task will complete with document no update version";
          ??? }catch(e){}
          ? }
          }
          -->
          </script>

          <body onbeforeunload="opCheckUnload();">
          </body>

          不過這種用法不支持firefox,因為firefox不支持window.event,所以本人改了一種方式,應(yīng)用如下:
          window.onbeforeunload = function() {
          ?? if(g_blnCheckUnload){
          ???? return("if close the window,the auto task will complete with document no update version!");
          ?? }
          }

          這樣幾種瀏覽器都支持了,彈出對話框如下:


          但這里有個問題,本來還沒有解決的,我用的瀏覽器是中文版,但我做的系統(tǒng)是英文版,這個事件彈出來的窗口所顯示的語言隨瀏覽器,沒有辦法自己在javascript里設(shè)置。

          posted on 2006-11-20 18:25 Jenny Li 閱讀(6092) 評論(3)  編輯  收藏 所屬分類: 技術(shù)文章

          FeedBack:
          # re: 關(guān)閉瀏覽器彈出對話框事件onbeforeunload
          2006-11-21 17:48 | Diego Tseng
          有用??!  回復(fù)  更多評論
            
          # re: 關(guān)閉瀏覽器彈出對話框事件onbeforeunload
          # re: 關(guān)閉瀏覽器彈出對話框事件onbeforeunload
          2010-02-04 16:02 | LZ忽悠
          LZ,你就忽悠吧!  回復(fù)  更多評論
            
          主站蜘蛛池模板: 哈尔滨市| 新田县| 宁蒗| 苏尼特左旗| 九寨沟县| 昌宁县| 沙田区| 金乡县| 天镇县| 长岛县| 雷山县| 延庆县| 呼和浩特市| 会昌县| 邹平县| 文化| 伽师县| 安国市| 延川县| 杂多县| 神木县| 洞口县| 晋城| 南木林县| 崇左市| 庄河市| 敖汉旗| 岳池县| 依兰县| 汨罗市| 怀来县| 公安县| 宿州市| 罗田县| 正镶白旗| 凯里市| 昌宁县| 云南省| 容城县| 阿克| 丰原市|