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

Discussion in 'Javascript' started by bobstead@blueyonder.co.uk, Jun 3, 2007.

  1. Guest

    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
     
    , Jun 3, 2007
    #1
    1. Advertising

  2. 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
     
    Peter Michaux, Jun 5, 2007
    #2
    1. Advertising

  3. On Jun 5, 9:15 pm, Randy Webb <> wrote:
    > Peter Michaux said the following on 6/5/2007 5:44 PM:
    >
    > > Hi Bob,

    >
    > You just earned a <smack> for not quoting!!!!


    My post was self contained :)

    Peter
     
    Peter Michaux, Jun 6, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Dalberg
    Replies:
    29
    Views:
    4,123
    kchayka
    Nov 3, 2004
  2. Jeff
    Replies:
    3
    Views:
    1,133
  3. Replies:
    8
    Views:
    241
    Randy Webb
    Jan 13, 2006
  4. patrickkellogg
    Replies:
    3
    Views:
    163
  5. Bob
    Replies:
    3
    Views:
    111
Loading...

Share This Page