Pop-up works in IE but fails in Firefox/Opera

B

bobstead

Hi Have tweaked a first script together which works fine in IE but
fails in FF/Opera would be grateful for any advise.

Script is as follows:

<script language="JavaScript" type="text/javascript">
function genopenpopup(width,height)
{
if (!width)
width = 900
if (!height)
height = 750
var popurl=event.srcElement.ref
winpops = window.open(popurl,"","width=" + width + ",height=" + height
+ ",scrollbars,resizable,")
if (winpops)
winpops.focus()
}
</script>

Each window coded thus:

<A href="#null" onclick="genopenpopup()" ref="catchments.pdf"
onmouseover="style.cursor='hand'">
9 Secondary School Catchments.</a></td></tr>

If () not specified window set at default of 900x750

Grateful for any feedback

Bob
 
P

Peter Michaux

Hi Bob,

In your script you assume that there is a global event variable that
contains the event object. This is true in IE but not all browsers.
The event object is available to the code in the onclick attribute
however so you can do this in IE and other browsers

onclick="genopenpopup(event);"

I would probably write your code something like this...

<script language="JavaScript" type="text/javascript">
function genopenpopup(url, width, height) {
winpops = window.open(url, "",
"width=" + (width||900) +
",height=" + (height||750) +
",scrollbars,resizable,");
if (winpops) {
winpops.focus();
}
}
</script>

Each window coded thus:

<a href="catchments.pdf" onclick="genopenpopup(this.href);return
false;" onmouseover="style.cursor='hand'">
9 Secondary School Catchments.</a>

I don't think you really need to focus winpopus after it is opened. It
will be focused normally. It probably doesn't hurt to focus it
however.

[JavaScript does have automatic semi-colon insertion but it is a good
practice to include them.]

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top