![]() If you can do that you may be able to pass the handle into a relatively non-scope-limited variable and call it later. Try opening a window with it, and in the opening window (not the new one) attempt to close it from the opener. ![]() Webview is notoriously difficult to work with so it may just simply not respond to that functionality or be buggy. The workaround is an attempt to create a handle for a window and use that handle to close it, despite security restrictions (due to spammers who opened and closed windows in web sites usually for ads or just to annoy people) that attempted to disable the ability to open or close windows in apps without user interaction - you may want to try to save the handle in a variable and see what you can do with it, like write to the window and see if the handle is not being lost. Otherwise you would have to effectively screen scrape and rewrite target pages to modify the links in them, but that can be very complicated. This method handles window popup security issues but not cross domain ones though (different security problem)… You could rewrite your own hyperlinks so they open in a different tab/window via link target, and then they would not ruin your original window – just people would have to hit a browser ‘x’ to close ones that you do not have control over in your first window. Secondary windows have different handles, and hyperlinks that are not javascripted with a window-open event do not save the handle of the windows they are opening. To make the close feature work, it needs an opener link that ‘catches’ the window reference handle that can be used to close it. The problem you are having sounds like not the first window, but subsequent ones, if I understand you correctly. The window-open and window-close method here uses these two and they need to match. So, addinge a simple alert, the code work well I was trying to investigate this, so i puttend some alert() to see wich line caused the crash. With this browser, infact, the page in wich the code is close itself instead of the opened one The problem exist for no browser than Microsoft Edge POPUP BLOCK IS ACTIVE, redirect the user to a page and ask him to enable popups Var test_open_windows = window.open(“”,”test_open_windows”,”width=1,height=1″) I use this code to check if the user have the popup enabled The opened window (window_to_close.htm): The launcher window (window_close_tester.htm): I tested using version 8.1 of Windows and Mac OS X 10.6, 10.9 & 10.10. I am calling it from a button press so it is **user initiated**, and it is still working fine using Chrome 35-40, Internet Explorer 11, Safari 7-8, and ALSO Firefox 35-40. The close option specification expects that it cannot be closed by anything other than the script that opened it… so this workaround basically attempts to reopen a window then close it: open(location, '_self').close() Most versions do not work anymore due to security restrictions. Be sure to click the ‘Open in New Window/Tab’ button on the page to open a new popup window, and then click the ‘Close This Window/Tab’ button on the newly opened window. A link to using script to open and script to close is included. You must use the complete code (HTML AND JAVASCRIPT BOTH!) for this to work. I have not seen any examples of modern browsers not working with this script if the above requirement has been met.įor those with hassles with window.close() or self.close() not working, there is a way for a JavaScript button to do this. If you are running any security programs, test the sample page first with them disabled if you are having issues. If you wish to close a page that has been posted via form, the page must first have still been opened in a separate window. NOTE: This script has 1 requirement that the page to be closed cannot be the original page.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |