How to close window in firefox using javascript?

后端 未结 4 470
小蘑菇
小蘑菇 2021-01-21 01:14

I am using top.window.close() to close the parent window but it is not working in Mozilla firefox.Please suggest alternatives. The above code is working fine for IE6.

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-21 01:39

    If you are using firefox profile you will be able to achieve it. Once it is updated in the firefox profile, it allows the firefox to be closed which is opened using the same profile.

    echo 'user_pref("dom.allow_scripts_to_close_windows", true);' >> $MOZILLA_PROFILE_DIR/prefs.js
    

    It works also if you add it in the user.js(Need to create this in the firefox profile directory).

    touch $MOZILLA_PROFILE_DIR/user.js
    echo 'user_pref("dom.allow_scripts_to_close_windows", true);' >> $MOZILLA_PROFILE_DIR/user.js
    

    And then start your firefox using the profile. You will be able to close the window by using javascript window.close()

    Remember: Without this you can't close the window which you have not opened using window.open()

提交回复
热议问题