window.open redirects the parent window to domain.com/0

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

window.open redirects the parent window to domain.com/0

Post by daedalus__ »

I have this bit of JS:

Code: Select all

function load()
{
	window.open("http://www.dancepropaganda.com/musicplayer/<?php echo preg_replace('/\s/', '_', $res['name']); ?>/player.html", width = 310, height = 250, status = 0, toolbar = 0, location = 0, menubar = 0, directories = 0, resizable = 0, scrollsbars = 0);
	return true;
}
window.onload = load();
When it is run, the window pops up but then the window that popped it up is redirected to http://www.domain.com/0

I do not understand why this is happening and cannot find anything about it on Google. :-/
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the width and height and all the rest of the properties need to all be in a single string.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

Thanks.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

It doesn't pop-up in IE, any suggestions? :-/
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I would imagine the popup blocker is blocking it, just like Firefox should too. I would suggest you let the user open the popup themselves, or use a ~floating div.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

/agree but the client thinks a pop-up window is best.

I've checked and checked and checked and no matter what I do, the attribute string will is not getting read correctly. I have to take it out entirely to get it to work in IE and FF. Oh well. :-/
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What's your new code?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Here is some syntax information on window.open. How is the function being called? Is it through an onLoad event, or onClick event, or what? onClick inside of an anchor html tag has a tendency to refresh the page it is on, which can be a bear sometimes. But look first at the syntax for window.open, then look at how the function is being called and how that event might be doing to you what is happening to you.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

Code: Select all

function popOnLoad(url)
{
	window.open(url, 'width=310, height=250');
	return true;
}
window.onload = popOnLoad("http://www.dancepropaganda.com/musicplayer/<?php echo $blah; ?>/player.html");
'width=310, height=250' doesnt work, having the attributes in any combination, wrapped in a string, doesn't work. It doesn't pop in IE and the attributes aren't read in FF. FF says 'invalid behavior' in the javascript console.

I also tried something like:

Code: Select all

function popOnLoad(url)
{
	window.open(url, width=310, height=250, attr=val);
	return true;
}
window.onload = popOnLoad("http://www.dancepropaganda.com/musicplayer/<?php echo $blah; ?>/player.html");
I think it had the same affect as above or didn't work in either browser.

EDIT: I actually decided to not worry about it to hard and am going to use a floating div when I have a moment to hack it up. I really just want this job to be done. :-/
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

window.open( string url, string windowName, string parameters);
Post Reply