Opening New Browser Windows with php?

Jan 27, 2002
149
0
71
Say I have a HTML form which contains a pulldown menu and a submit button.

When you submit the form, I want some php to open 1-4 new browser windows with different urls depending on what the choice in the pdm was.

Can anyone tell me how?

Just a function name will be enough, thanks!
 

jjones

Lifer
Oct 9, 2001
15,424
2
0
I could most definately be wrong, but I don't think php has a new window function because it's server side, not client side. I think you'll need to go with some java script to do what you want.
 

TechBoyJK

Lifer
Oct 17, 2002
16,699
60
91
haha, i need to almost the same thing with cfm. i have an app that generates urls, and they need to be opened up as new windows in the default browser.....
 

statik213

Golden Member
Oct 31, 2004
1,654
0
0
Make php echo javascript to open a new window. Trigger it on page load.
In the head tag:
echo "
<script>
function foo(){
window.open('http://some.place.com');
}
</script>";

and your body tag should like:

<body onLoad='foo();' ]

Off course, pop-blockers will stop this.
 

kukyfrope

Senior member
Mar 21, 2005
344
0
0
Your best solution is JavaScript. No two-ways about it if you're generating a new window from a pulldown menu.
 

Cheetah8799

Diamond Member
Apr 12, 2001
4,508
0
76
As others have already said, you do this with javascript.

Reason is because PHP is a server-side language. It only runs code on the server. Opening another window is something done no the client-side. So you would use javascript, maybe vbscript as well because those are client-side languages.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: statik213
Make php echo javascript to open a new window. Trigger it on page load.
In the head tag:
echo "
<script>
function foo(){
window.open('http://some.place.com');
}
</script>";

and your body tag should like:

<body onLoad='foo();' ]

Off course, pop-blockers will stop this.
I wouldn't send a whole new page back to the user with the window popping javascript. If possible, I'd actually try to pop them up directly from the forms page. A pop-up as a result of a user action is even less likely to be blocked and then you don't leave the user on an empty base page (unless, of course, you had something different you wanted to show them anyways).
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: TechBoyJK
here yea go
I know I'm being picky, but I just thought I'd take the liberty of making the code a little bit more standards compliant :p

I took the liberty of removing the credits because it's such a trivial piece of code, nobody should get credit for it. Also, there may be more issues if you were trying to achieve xhtml compliance. This one should be fine (as it has no &, < or " characters in it) but I believe the compliant way to do it (if you did) would be to wrap the script in <![CDATA[ ... ]>. Never tested it, but I bet IE would baulk at that :p
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Clarification on the CDATA:

xhtml is valid xml. You are not allowed to have certain characters at random points within an xml document. &, for instance, starts an escape sequence like & nbsp; and < always starts a new tag. If you want to use these in your javascript you must use them in such a way that does not violate the rules of xml. One way is to actually use escape sequences so & would be replaced with & amp; (or the corresponding number for &) and < would be replaced with & lt; (or the corresponding number). That makes javascript very hard to write and read so xml has a construct called CDATA (character data) which allows you to put arbitrary characters in it. You start a CDATA block with the sequence <![CDATA[ and end it with ]]> (being carefull not to use ]]> within your CDATA :p).

The reason I think IE would baulk at this is that IE doesn't really handle xml very well. You can give it xhtml and it will treat it as regular html (tag soup) and will get by fine with it's error handling, but I'm guessing this is a little too bizarre for it. Anyways, this is way too complicated for the original question. Use html 4.x and you'll be fine :)

Edit: I had to fix all the escape sequences because fusetalk messes them up. Imagine them without the space between the ampersand and the rest of the word.
 

statik213

Golden Member
Oct 31, 2004
1,654
0
0
Originally posted by: kamper
Originally posted by: statik213
Make php echo javascript to open a new window. Trigger it on page load.
In the head tag:
echo "
<script>
function foo(){
window.open('http://some.place.com');
}
</script>";

and your body tag should like:

<body onLoad='foo();' ]

Off course, pop-blockers will stop this.
I wouldn't send a whole new page back to the user with the window popping javascript. If possible, I'd actually try to pop them up directly from the forms page. A pop-up as a result of a user action is even less likely to be blocked and then you don't leave the user on an empty base page (unless, of course, you had something different you wanted to show them anyways).


Well, according to the OP, the logic for pages to be opened are on the server-side (i.e. after the form is submitted)... I think the OP needs to have some results returned to the same page and a few other windows opened as well.
I guess you could submit the form using AJAX and then open the pages based on that result....
 

statik213

Golden Member
Oct 31, 2004
1,654
0
0
can you post your code? Are you sure you included a call to your javacsript function on the onLoad of the body of the document?
i.e. if the function to open the windows is called load:
<body onLoad="load();"];

Note: the ] should be a >, fusetalk doesn't like HTML tags..
 

TechBoyJK

Lifer
Oct 17, 2002
16,699
60
91
Originally posted by: statik213
can you post your code? Are you sure you included a call to your javacsript function on the onLoad of the body of the document? i.e. <body onLoad="load();"];

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>

<body>

<script type="text/javascript">
function load() {
var load = window.open('http://www.domain.com','','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
}
</script>




</body>
</html>


 

TechBoyJK

Lifer
Oct 17, 2002
16,699
60
91
I'm using crazy browser and mozilla, and I just want the new window to open up in a new tab automatically...
 

statik213

Golden Member
Oct 31, 2004
1,654
0
0
Should be:
where on**Load is onLoad

HTML:
[head]
	[title] Untitled [/title]

[script type="text/javascript"]
  function load() {
    var load = window.open('[url="http://www.domain.com/"]http://www.domain.com/[/url]','','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
  }
[/script]

[/head]

[body on**Load="load();"]
[/body]

 

statik213

Golden Member
Oct 31, 2004
1,654
0
0
SOrry about teh fvcked up code, how is it that your able to post full html? Fusetalk gives me hell when I try to include html tags.
 

TechBoyJK

Lifer
Oct 17, 2002
16,699
60
91
Originally posted by: statik213
Should be:
where on**Load is onLoad

HTML:
[head]
	[title] Untitled [/title]

[script type="text/javascript"]
  function load() {
    var load = window.open('[url="http://www.domain.com/"]http://www.domain.com/[/url]','','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
  }
[/script]

[/head]

[body on**Load="load();"]
[/body]

*bullseye*
 

TechBoyJK

Lifer
Oct 17, 2002
16,699
60
91
Originally posted by: statik213
SOrry about teh fvcked up code, how is it that your able to post full html? Fusetalk gives me hell when I try to include html tags.

its ok, i just did a replace with [ for < and vice versa..... how do I do it? its a secret! unfortunately, i don't know the secret...
 
Jan 27, 2002
149
0
71
Geez!
This thread really took off a few hours after I posted/waited/got fed up/went to watch footy.

It's obvious to me now that javascript, being client side, was the best way. I just thought that maybe when using the 'header(Location: $url)' I could throw in some sort of function which redirected 4 times to new windows or something?

Anyway, thanks for all the answers(if anyone's still reading)!