Forum Moderators: coopster

Message Too Old, No Replies

Control new browser window size in PHP?

         

aus_dave

1:14 am on Apr 29, 2003 (gmt 0)

10+ Year Member



I'm editing a PHP page that contains a link to other PHP pages using a standard <a href= etc.> tag, that contains an array variable with the page URLs.

I want this link to open in a new window and to be able to control the size of it in the script. I can't get the usual Javascript function to work and a quick search tells me this is not unexpected!

Are there any easy ways to control the size of the resultant browser window in PHP?

[edit] Worked out how to do it - needed to use \ in front of the " quotes - don't know how I missed that :)[/edit}

ShawnR

1:57 am on Apr 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or use different quotes (" vs ')

aus_dave

4:56 am on Apr 29, 2003 (gmt 0)

10+ Year Member



I cut and pasted the same code I always use for Javascript windows but it didn't work where I substituted single quotes for double quotes. I'm a PHP beginner so I don't know why but it worked when I left the double quotes in with the \ :).

ShawnR

5:27 am on Apr 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I gotcha. Single quoting will prevent your variables from evaluating, and just treat them as literal strings. If the single quotes are on the outside and the double quotes are on the inside, the whole string is taken literally. Should work OK if the doubles are on the outside, and the singles are on the inside, but it depends on the particulars of the string being printed...

Shawn

aus_dave

5:45 am on Apr 29, 2003 (gmt 0)

10+ Year Member



That is exactly right Shawn :). I'll post the simplified code in case this helps someone out in future:

<a href=\"javascript:;\" onClick=\"MM_openBrWindow('/$link[$seq]','window properties')\">

ShawnR

6:24 am on Apr 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, so the problem is you need 3 sets of quotes: 1 to enclose the php string, 1 to enclose html attrib values, and 1 to enclose your string arguments to your javascript function, which is itself an html attrib value. Here is one suggestion to avoid escaping the quotes and make it more readable:
<?php 
echo <<<END
<a href="javascript:;" onClick="MM_openBrWindow('/$link[$seq]','window properties')">
END;
?>

Note that you could write the <A> tag as follows:


<a href="javascript:MM_openBrWindow('/$link[$seq]','window properties')">

Shawn