IndianaGuy Posted December 26, 2016 Share Posted December 26, 2016 Why would the window.close() not work in Safari mobile on iPhones? I don't have anything complicated. Just a button to run a function on click. The function so far has nothing more than window.close(); Link to comment Share on other sites More sharing options...
Ingolme Posted December 26, 2016 Share Posted December 26, 2016 A script can only close windows that it created using window.open(). This was a security feature to prevent websites from closing windows without the user's permission. Link to comment Share on other sites More sharing options...
IndianaGuy Posted December 26, 2016 Author Share Posted December 26, 2016 (edited) Ok, so tell me if I am thinking about this right. Page 1- The user can open a window to go to page 2 Page 2 can have a script that will close page 2? What should the value of the new target page be? _blank, _parent _self, _top, _name, or does it matter. Does the actual code to close page 2 has to be coded in page 1.? Thank you so much. Edited December 26, 2016 by IndianaGuy Link to comment Share on other sites More sharing options...
Ingolme Posted December 26, 2016 Share Posted December 26, 2016 _blank, _parent, _self and _top are options that you should choose based on what you want your page to do. Do you understand what each of them means? If not, then you should look through the reference, there's no point in using something if you don't know what it does. Here's the page that describes each of the options: http://www.w3schools.com/jsref/met_win_open.asp I actually have not experimented with pages that close themselves, so I can't tell for sure if page 2 will be allowed to close itself after being opened by a script from page 1, but if you want to be safe, the script to close page 2 should be in page 1. You can have a function declared on page 1 that is called from page 2. Page 2 should have access to methods declared on page 1 by using the window.opener property. Link to comment Share on other sites More sharing options...
IndianaGuy Posted December 27, 2016 Author Share Posted December 27, 2016 Lots of great points. I am getting over my head here and I am sure you will have a simpler solution for me. This is a simple thing. the user is listening to a media file. We absolutely have to know when the user stops listening to the audio file based on possible actions. Buttons to make the audio stop playing are easy to record the currentTime. However, what can we do about the current time when the window is closed? I am open to any solutions. multiple pages, iframes etc etc . All this is for mobile devices only. Thank you Link to comment Share on other sites More sharing options...
Ash! Posted December 27, 2016 Share Posted December 27, 2016 Hi, I'm no expert in JS but I'd like to suggest something. This might not be the best solution but here it goes... What you want to do is record the currentTime of the media when user closes the window, right? An AJAX request might not work on beforeunload I guess. What you can try is....save the curerntTime to the localStorage every second using the setInteval method. The currentTime stays in the localStorage when the user closes the window. But when the user comes back to your site, you can retrieve it from localStorage and store in your database using AJAX. I'm not sure if that would help Link to comment Share on other sites More sharing options...
dsonesuk Posted December 27, 2016 Share Posted December 27, 2016 Instead of window.close() try self.close(); it should close the window that called the function, you might have click 'OK' to verify on some browsers, but the function can be in the page to close itself or externally linked. Link to comment Share on other sites More sharing options...
IndianaGuy Posted December 27, 2016 Author Share Posted December 27, 2016 Great ideas worth exploring and doing some research. Thank you all very much. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now