Jump to content

window.close


IndianaGuy

Recommended Posts

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

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
Link to comment
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.

Link to comment
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

Link to comment
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:

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...