javascript的window.close()在Google和Firefox下失效

來源:互聯網
上載者:User

標籤:地址欄   無效   pts   firefox   不能   set   str   sel   window   

   在一次使用setTimeout(‘window.close()‘,5000)對視窗進行關閉時遇到問題:不能關閉視窗   解釋:

   為了阻止惡意的指令碼終止使用者的瀏覽器。只有通過 JavaScript 代碼開啟的視窗才能夠由 JavaScript 代碼關閉,如某個視窗可以通過調用 self.close() 或只調用 close() 來關閉其自身。 在IE中,window.close()能生效, 對Google可按照下面代碼使其生效 window.open(‘‘,‘_self‘,‘‘); window.close(); 先通過window.open()在本視窗開啟一個頁面,然後再通過window.close()方法關閉。 但是在Firefox下面無效。

需要對Firefox進行如下操作:

1.在Firefox地址欄裡輸入 about:config

2.在配置列表中找到 dom.allow_scripts_to_close_windows

3.點右鍵的選切換把上面的false修改為true即可。 註:預設是false,是為了防止指令碼亂關視窗

javascript的window.close()在Google和Firefox下失效

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.