Forum Moderators: open

Message Too Old, No Replies

Popup won't open in IE but will on a Mac

         

josaiah

8:11 am on Dec 1, 2007 (gmt 0)

10+ Year Member



Hi, I'm new to this so if i make any mistakes, i beg your pardon.

I have a site which depends heavily on popups and the main page is supposed to be a customized popup activated by javascript. The issue is that although the popup works on safari/camino/macs in general, it brings up an "error on page" when windows users click it. here's the code:

<script>
function enterSite(){
var left=(screen.width-1024)/2;
var top=(screen.height-700)/2;
var newWin=window.open("x.html", "x", "scrollbars=0, status=0, width=1024, height=768, resize=0, top="+top+", left="+left);}
</script>

and here's the trigger:

<area shape="rect" coords="15,29,895,382" href="#" onClick="enterSite();" target="_self">

i know it's not a problem with x.html because when i type in the url directly it loads fine. would really really really appreciate it if someone could help me out with this...thanks!

rocknbil

6:55 pm on Dec 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard josaiah! I don't know if this will help, but a few comments. First if you see error on page - did you open the error alert to see what it is? Does this happen in FireFox? FireFox has a much more descriptive error control panel.

try changing this
<script>
to this
<script type="text/javascript">

Secondly, this
var left=(screen.width-1024)/2;
var top=(screen.height-700)/2;

relies on the browser supplying screen.width and screen.height. What if those values are not supplied by the browser? Modify it as so:

var left = (screen.width)?(screen.width-1024)/2:500;
var top = (screen.height)?(screen.height-700)/2:500;

What this says is, "if screen.width is present, set left to my calculation, if it's not, set it to 500 pixels." This will always provide a default value regardless of what browser opens it.

Also resize is not a valid window parameter - see comments below.

I have a site which depends heavily on popups

This is a bad idea on two levels - one, if Javascript is disabled the user won't get the content, and two, popups are a matter of distain by many users. But all is not lost. You only need to make a few minor changes so that whatever is in your popups is accessible with or without Javascript. First, you'd change this

<area shape="rect" coords="15,29,895,382" href="#" onClick="enterSite();" target="_self">

to this:

<area shape="rect" coords="15,29,895,382" href="x.html" onClick="return enterSite();" target="new window">

The deal here is that if Javascript is disabled or fails, the actual link will move the browser to x.html and open it in a new window. If Javascript is functioning properly, the return will expect a false value from the Javascript function. This will tell the browser not to execute the action of the link - so it will be the same as #, the link won't move off the page.

For this to work we need to add return false to your function:

return false;
</script>

Those two changes and you have accessible Javascript.

I would also recommend always making a window resizable, and with scrollbars. I know this is a design consideration, but you never know your user's environment - although it fits perfectly on everything you test, the possibility ALWAYS exists someone may open it and it will not.

As mentioned resize is not a valid parameter, and to add or not add parameters you don't need to specify "0" or "1" - simply include, or don't include, the parameter:

var day = new Date();
var id = day.getTime();
var params='width=1024,height=768,resizable,scrollbars,top='+top+',left='+left;
var newWin=window.open('x.html',id,params);

My little add-on for id - this will always guarantee the content will open in a NEW window instead of one named "x". :-)

josaiah

10:34 am on Dec 2, 2007 (gmt 0)

10+ Year Member



alrighty thanks so much for the help :) it certainly makes my site quite accesible now. anyhows, i implemented your code changes but i still get the error:

Invalid argument on line 24, char 2, syntax error, error code: 0

with line 24 being

var newWin=window.open("x.html", "x", "scrollbars=0, status=0, width=1024, height=768, resize=0, top="+top+", left="+left);

but at least now although the error occurs the new window pops up as a normal href. the error still irritates me though. i've fixed this before just by adding one character but unfortunately i've lost the file hehe. it works fine in firefox both on a mac and a pc. is it just me or is IE6 a real pain in the butt! does anyone see where the mistake is? i'm posting the beginning of the code too just in case.

<html>
<head>
<title>X</title>
<link rel="shortcut icon" href="favicon.ico" >
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/javascript">

rocknbil

12:09 pm on Dec 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



the new window pops up as a normal href.

If you added this

return false;
</script>

This is only happening because the script errors and won't run.

Curious, I put your original code in a file, getting no errors in IE 7 or FF (6 is on another machine here.) However,

Invalid argument on line 24, char 2, syntax error, error code: 0

Did you change it to resizable?

..... width=1024, height=768, resize=0, top="+top+",

josaiah

1:51 pm on Dec 2, 2007 (gmt 0)

10+ Year Member



yep tried to change it to resizeable, still nothing. i know it seems a little stubborn on my part to insist on having all the scrollbars and resizeable blablabla parts trimmed down, but i already have a link to the main site which doesn't have a popup, so yeah. still nothing :(