View Full Version : Passing vars to javascript window.open()

02-23-2009, 09:37 AM

I want to pass window size variables to javascript's window.open() function from a flash movie (actionscript) to javascript embedded in an html page. The idea is to generate a pop-up window when the user clicks a button in the flash movie. I've programmed the flash movie button like this:

on (release) {
getURL("javascript:open_win('http://www.mysite.com', winfeatures)"); }

where winfeatures is a string containing the pop-up window options, e.g. width=400,height=300,resizable=1 . I have 'traced' the string to make sure it is formed properly. These variables may change so I don't want to just insert them verbatim as the arguments. They are read from an xml file and made into a string - e.g. (var winfeatures:String = "width="+myxml.attributes.width+",height="+myxml.attributes.height);

In the html page I have the following javascript:

function open_win(URLtoOpen, windowFeatures) {
newWindow=window.open(URLtoOpen, "myWin", windowFeatures);

but it's not working. It seems the windowFeatures isn't being read (or read properly) and the pop-up opens with a default size.

Can anyone tell me what I'm doing wrong?


02-23-2009, 11:20 AM
Flash will not recognize a variable inside of a string like that, try this.

on (release) {
getURL("javascript:open_win('http://www.mysite.com', " + winfeatures + ")"); }

02-23-2009, 01:37 PM
Jeremy - thanks for your quick reply. Unfortunately though, it's still not working - it still opens the pop window with a default size.

Could it be the formation of the winfeatures string in the actionscript? This is how I form it:
winfeatures = "height="+myxml[0].attributes.height+",width="+myxml[0].attributes.width+",resizable=1,scrollbars=1";

Or am I perhaps missing something on the javascript in the html page?