Jump to content
IndianaGuy

window.close

Recommended Posts

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();

 

 

 

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 by IndianaGuy

Share this post


Link to post
Share on other sites

_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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 :Unsure:

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...