Page 1 of 1

JavaScript: window.open problem [SOLVED]

Posted: Mon Jun 26, 2006 4:02 am
by aerodromoi
Right now I'm using a short JavaScript function (called from an external file) on my page to call a popup.

Code: Select all

function popimage(urlv,namev,hi,wi){
var newwindow ="";
newwindow=window.open(urlv,namev,'height='+hi+',width='+wi+',resizable=yes,toolbar=no,location=no,scrollbars=yes');
newwindow.focus();
}

Code: Select all

<a href="img.jpg" onclick="popimage('img.jpg','img','496','656'); return false;" target="_new">link</a>
However, even though the function works in Firefox 1.5, the console shows a syntax error in line one and the MSIE debugger complains about an invalid argument in line 4 (3rd character).

I'd appreciate any suggestions.

aerodromoi

Posted: Mon Jun 26, 2006 4:21 am
by Benjamin
One of your variable names is conflicting with IE. Change the name(s) of your variables in the function calls.

Posted: Mon Jun 26, 2006 4:38 am
by aerodromoi
astions wrote:One of your variable names is conflicting with IE. Change the name(s) of your variables in the function calls.
I've changed the name of the function and the names of the variables - the error message remains the same.

Code: Select all

function pop_image(urlvar,namevar,hivar,wivar){
  var pwindow = '';
  pwindow=window.open(urlvar,namevar,'height='+hivar+',width='+wivar+',resizable=yes,toolbar=no,location=no,scrollbars=yes');
  pwindow.focus();
}
aerodromoi

Posted: Mon Jun 26, 2006 4:42 am
by Benjamin
It must be a syntax error in 'height='+hivar+' then.

I'm not a JS expert so I can't help more than that.

Posted: Mon Jun 26, 2006 1:52 pm
by tecktalkcm0391
Dunno anything about JS, but I found this on google:

[quote=developer.apple.com/internet/ webcontent/eventmodels.html"]To avoid conflict with the IE window.event object, do not use event as the parameter name. [/quote]

Also try reading this: http://www.sitepoint.com/forums/showthread.php?t=396443

Posted: Mon Jun 26, 2006 9:21 pm
by HCBen
You're activating too many window events at once. Simplify the code. Try this:

Code: Select all

function pop_image(url,windowname,height,width){
window.open(url,windowname,'height='+height+',width='+width+',resizable=yes,toolbar=no,location=no,scrollbars=yes');
}

<a href="javascript:pop_image('url','windowname','height',width')">link</a>
You shouldn't need to use a focus method. The window.opener method should automatically open any new window above the current window with focus.

Give this a shot.

Ben

Posted: Tue Jun 27, 2006 3:29 am
by aerodromoi
tecktalkcm0391 wrote:Dunno anything about JS, but I found this on google:
developer.apple.com/internet/ webcontent/eventmodels.html wrote:To avoid conflict with the IE window.event object, do not use event as the parameter name.
Also try reading this: http://www.sitepoint.com/forums/showthread.php?t=396443
That's why "event" wasn't even mentioned ;) The height and width data are passed to the function via a php script. There's no need to handle that on the client side.

Just for testing purposes I've stripped it down somewhat and it works now.

Code: Select all

function pimage(urlvar){
  window.open(urlvar,'newimage','height=480,width=640,resizable=yes,scrollbars=yes');
}
So off I go rebuilding the function (slowly, this time).

Thnx,
aerodromoi