JavaScript: window.open problem [SOLVED]

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

JavaScript: window.open problem [SOLVED]

Post 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
Last edited by aerodromoi on Tue Jun 27, 2006 9:28 am, edited 1 time in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

One of your variable names is conflicting with IE. Change the name(s) of your variables in the function calls.
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post 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
User avatar
HCBen
Forum Commoner
Posts: 33
Joined: Thu Jun 22, 2006 3:15 pm
Location: Indiana

Post 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
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post 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
Post Reply