iT邦幫忙

0

請問程式抓IE[x]關閉符號時可以不要出現警告嗎?

大家好 , 小弟想請問一下
我用window.showModalDialog開啟了一個頁面 , 我在關閉X的地方寫了一個去按某個button後回傳資訊給母窗的動作 , 在關閉子窗 ,但它關子窗的時後都會出現詢問是否關閉的!! 是否有方法可以不跳出詢問呢 ? ...以下是我按下xx的程式是這樣寫..
有試過window.onbeforeunload = undefined 才不會跳,但我的returnValue = o 就無法回傳了....是否先進有更好的建議可以幫幫小弟呢...謝了

 <script type="text/javascript">
     function closeThisWindow(FleetCode, FleetCode1, FleetCode2) {
         var o = new Object();
         o.FleetCode = FleetCode;
         o.FleetCode1 = FleetCode1;
         o.FleetCode2 = FleetCode2;
         window.returnValue = o;
         window.close();
     }    
 </script>
     <script type="text/javascript" language="javascript">
         window.onbeforeunload = CloseWindows;
         function CloseWindows() {
             //按下X關閉 
             if (event.clientY < 0) {
                 try {
                     document.getElementById('<% =button3.ClientID%>').click();
                      return true;               
                 }
                 catch (e) {
                     alert('close windows error message:' + e.message);
                 }
             }
         }     
</script>
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

6
player
iT邦大師 1 級 ‧ 2013-12-09 15:07:15
最佳解答
sundayjoe iT邦新手 5 級 ‧ 2013-12-09 15:44:54 檢舉

試了 以下的都沒法讓它不出現耶
void(window.open('','_parent',''));
window.opener=null;
window.close;

怪了 ... 不知還有別的方法 嗎~~謝謝

sundayjoe iT邦新手 5 級 ‧ 2013-12-09 15:46:09 檢舉

4
funforever
iT邦新手 4 級 ‧ 2013-12-10 22:48:39

能將子母程式的sourcecode全部分享出來看看嗎?

問題看起來不像是出現在javascript上

看更多先前的回應...收起先前的回應...

小弟我沒看仔細

<pre class="c" name="code"> <script type="text/javascript">
     function closeThisWindow(FleetCode, FleetCode1, FleetCode2) {
         var o = new Object();
         o.FleetCode = FleetCode;
         o.FleetCode1 = FleetCode1;
         o.FleetCode2 = FleetCode2;
         window.returnValue = o;
         window.close();
     }    
 </script>
     <script type="text/javascript" language="javascript">
         window.onbeforeunload = CloseWindows;
         function CloseWindows() {
window.event.returnValue==true;//加上這段,是否可行??             
//按下X關閉 
             if (event.clientY < 0) {
                 try {
                     document.getElementById('<% =button3.ClientID%>').click();
                      return true;               
                 }
                 catch (e) {
                     alert('close windows error message:' + e.message);
                 }
             }
         }     
</script>

奇怪 我拿你的code來試 並沒有跳視窗詢問我...
我不懂..-.-
在努力試試吧...加油...

你有試過把

<pre class="c" name="code">if (event.clientY < 0) {
                 try {
                     document.getElementById('<% =button3.ClientID%>').click();
                      return true;               
                 }
                 catch (e) {
                     alert('close windows error message:' + e.message);
                 }
             }

這段移掉嗎...
我看起來感覺好像可以...
你可以試試看...

sundayjoe iT邦新手 5 級 ‧ 2013-12-11 01:35:16 檢舉

1.加上 ; window.event.returnValue==true;//加上這段,是否可行?? (也是一樣)
2.我if (event.clientY < 0) 是要抓使用者按下 ie [x] 用的 , 不加的話會正常沒錯,但就無法自動去按BUTTON3了..
我是用IE7 ....
我繼續TYY

sundayjoe iT邦新手 5 級 ‧ 2013-12-11 01:52:29 檢舉

忘了說 , 我的Button3就是去計算一些東西然後最後觸發上面的function closeThisWindow , 在傳回去母頁面 ....

新版IE因為安全性的關係,要關閉頁面一定會出現詢問,無法以此類方式達到無警示關閉。

sundayjoe iT邦新手 5 級 ‧ 2013-12-13 09:06:40 檢舉

不會吧 . 看來不是裝沒看見就是改別的方式了

謝謝

player iT邦大師 1 級 ‧ 2013-12-13 16:23:46 檢舉

sundayjoe提到:
window.event.returnValue==true

這行有2個= 是比較?
是不是寫錯了? 給值用1個 = 就好了

啊 應該是給一個“=”就好
感謝指正臉紅

&lt;pre class="c" name="code">
if (event.clientY &lt; 0) {  
                 try {  
                     document.getElementById('&lt;% =button3.ClientID%>').click();  
                      return true;                 
                 }  
                 catch (e) {  
                     alert('close windows error message:' + e.message);  
                 } 

要塞值回母頁面可以用其他方法
不需要上段程式碼

我的意思是說
您可以考慮一樣傳回值不管是0 or 1
但是當值到了 母畫面你再決定判斷式
而傳直回去的function 寫在這個“ event.clientY < 0”的判斷式之外
這判斷式移除 應該可以達到你想要的目的

另外window.event.returnValue=true; 也只是為了直接跳過下面判斷式而加的function
有機會再研究看看 加油

我要發表回答

立即登入回答