/    Sign up×
Community /Pin to ProfileBookmark

window.close and location.replace

This one has me pretty tangled. I’ve scaled the code down for gut level editing.

Basically, my site has two windows. One is a frame and the other, a popup. Both play my webcast. Because popup blockers (a good thing) will block my popup, I start with audio from my webcast in the frame. There is a button which will open the webcast in a non-blocked popup.

If they open the window, the frameset automatically stops playing. If they close the popup, the frameset reloads and plays again.

The problem: if the popup is open and the visitor closes the main window (opener window) I get an error message “permission denied, code 0”.

I think this is because the webcast window is trying to load the frameset location … but the frameset no longer exists because the window has been closed. 😮

Can anyone help me find a solution to rid me of the error message?

[CODE]var alternate = “null”;
if (window.name == ‘webcast’) alternate = opener.parent.hidden; // hidden is the name of the opening window

// at page UNLOAD

window.onunload = function()
{
if (window.name == ‘webcast’ && alternate.location.href == “http://www.robindean.com/index.php?play=false”) alternate.location.replace (‘index.php?play=webcast’);
if (window.name == ‘hidden’ && !webcast.closed && webcast.location && window.location.href == “http://www.robindean.com/index.php?play=false”) webcast.close();
}[/CODE]

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@CrazyMerlinMar 31.2007 — just check to see if the parent window is open before trying to use it.

you can do this in multiple ways, the most efficient being the [B]typeof [/B]operator.

something along the lines of:

if('window' == typeof window.parent)

check it out.
Copy linkTweet thisAlerts:
@robindeanauthorMar 31.2007 — Thanks Merlin. I'll read up.

If the popup is named 'webcast' ... how do I tell 'webcast' to check and see if it's parent still exists?

I only ask so that either you or someone else might beat me to the punch while I read up in google.
Copy linkTweet thisAlerts:
@Mr_JMar 31.2007 — You could try this check

if(opener&&!opener.closed)
Copy linkTweet thisAlerts:
@robindeanauthorMar 31.2007 — I had just thought of that and was suspicious of it giving me trouble ... but it worked ?

Thanks to both of you.
Copy linkTweet thisAlerts:
@robindeanauthorMar 31.2007 — darn it ... if (opener && !opener.closed) isn't working.

It seems as if there's a split second in time where the window "seems" to be still open.
×

Success!

Help @robindean spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...