Open new window with JS

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Aitken

    #1

    Open new window with JS

    I want to include a button that has rollover effects and also is a link to a
    page that will open in a new window. Here's the code I am using:

    <A
    HREF="javascrip t:window.open(' email_me.htm',' ','scrollbars=0 ,menubar=0,heig h
    t=260,width=400 ,toolbar=0');"
    ONMOUSEOVER="ch angeImagesX('Em ailMe_Layer_1',
    'images/EmailMe_Layer-1-over.gif'); return true;"
    ONMOUSEOUT="cha ngeImagesX('Ema ilMe_Layer_1', 'images/EmailMe_Layer-1.gif');
    return true;">
    <IMG NAME="EmailMe_L ayer_1" SRC="images/EmailMe_Layer-1.gif" BORDER=0
    width="140" height="25"></A>

    Everything works OK - the rollovers work and when the button is clicked the
    new window opens. The problem is that the original window goes blank and
    displays only the text [object]. How can I do what I want and have the
    original window retain its contents?

    You can see this at http://www.pgacon.com/testpage.htm

    --
    Peter Aitken

    Remove the crap from my email address before using.


  • Lee

    #2
    Re: Open new window with JS

    Peter Aitken said:[color=blue]
    >
    >I want to include a button that has rollover effects and also is a link to a
    >page that will open in a new window. Here's the code I am using:
    >
    ><A
    >HREF="javascri pt:window.open( 'email_me.htm', '','scrollbars= 0,menubar=0,hei gh
    >t=260,width=40 0,toolbar=0');"
    > ONMOUSEOVER="ch angeImagesX('Em ailMe_Layer_1',
    >'images/EmailMe_Layer-1-over.gif'); return true;"
    > ONMOUSEOUT="cha ngeImagesX('Ema ilMe_Layer_1', 'images/EmailMe_Layer-1.gif');
    >return true;">
    > <IMG NAME="EmailMe_L ayer_1" SRC="images/EmailMe_Layer-1.gif" BORDER=0
    >width="140" height="25"></A>
    >
    >Everything works OK - the rollovers work and when the button is clicked the
    >new window opens. The problem is that the original window goes blank and
    >displays only the text [object]. How can I do what I want and have the
    >original window retain its contents?[/color]

    The HREF attribute tells the link what to display in the current
    window. You're telling it to display the value returned by the
    javascript method "window.open(.. .)". That value is a window
    object, which displays as "[object]".

    If you don't want to display the value of a Javascript expression,
    don't use the "javascript :" protocol. If you don't want to change
    the contents of the current window at all, have the onclick handler
    of the link return false.

    This also makes it possible for people to use the link if they
    don't have Javascript enabled.

    <a href="email_me. htm"
    onclick="window .open('email_me .htm','validNam e','height=260, width=400);retu rn
    false"
    onmouseover="ch angeImagesX('Em ailMe_Layer_1', 'images/EmailMe_Layer-1-over.gif');
    return true;"
    onmouseout="cha ngeImagesX('Ema ilMe_Layer_1',' images/EmailMe_Layer-1.gif');
    return true;"><img
    name="EmailMe_L ayer_1"
    src="images/EmailMe_Layer-1.gif"
    border="0"
    width="140"
    height="25"></A>

    Comment

    • Peter Aitken

      #3
      Re: Open new window with JS

      "Lee" <REM0VElbspamtr ap@cox.net> wrote in message
      news:cbuv0s02te l@drn.newsguy.c om...[color=blue]
      > Peter Aitken said:[color=green]
      > >
      > >I want to include a button that has rollover effects and also is a link[/color][/color]
      to a[color=blue][color=green]
      > >page that will open in a new window. Here's the code I am using:
      > >
      > ><A[/color]
      >
      >HREF="javascri pt:window.open( 'email_me.htm', '','scrollbars= 0,menubar=0,hei g[/color]
      h[color=blue][color=green]
      > >t=260,width=40 0,toolbar=0');"
      > > ONMOUSEOVER="ch angeImagesX('Em ailMe_Layer_1',
      > >'images/EmailMe_Layer-1-over.gif'); return true;"
      > > ONMOUSEOUT="cha ngeImagesX('Ema ilMe_Layer_1',[/color][/color]
      'images/EmailMe_Layer-1.gif');[color=blue][color=green]
      > >return true;">
      > > <IMG NAME="EmailMe_L ayer_1" SRC="images/EmailMe_Layer-1.gif" BORDER=0
      > >width="140" height="25"></A>
      > >
      > >Everything works OK - the rollovers work and when the button is clicked[/color][/color]
      the[color=blue][color=green]
      > >new window opens. The problem is that the original window goes blank and
      > >displays only the text [object]. How can I do what I want and have the
      > >original window retain its contents?[/color]
      >
      > The HREF attribute tells the link what to display in the current
      > window. You're telling it to display the value returned by the
      > javascript method "window.open(.. .)". That value is a window
      > object, which displays as "[object]".
      >
      > If you don't want to display the value of a Javascript expression,
      > don't use the "javascript :" protocol. If you don't want to change
      > the contents of the current window at all, have the onclick handler
      > of the link return false.
      >
      > This also makes it possible for people to use the link if they
      > don't have Javascript enabled.
      >
      > <a href="email_me. htm"
      >[/color]
      onclick="window .open('email_me .htm','validNam e','height=260, width=400);retu r
      n[color=blue]
      > false"
      >[/color]
      onmouseover="ch angeImagesX('Em ailMe_Layer_1', 'images/EmailMe_Layer-1-over.gi
      f');[color=blue]
      > return true;"
      >[/color]
      onmouseout="cha ngeImagesX('Ema ilMe_Layer_1',' images/EmailMe_Layer-1.gif');[color=blue]
      > return true;"><img
      > name="EmailMe_L ayer_1"
      > src="images/EmailMe_Layer-1.gif"
      > border="0"
      > width="140"
      > height="25"></A>
      >[/color]

      Thanks for the info, Lee - it helped but it is still not right - the new
      page opens in the original browser window instead of a new window. Here's
      the code:

      <a href="email_me. htm"
      onclick="window .open('email_me .htm','validNam e','height=260, width=400);retu r
      n false;"
      onmouseover="ch angeImagesX('Em ailMe_Layer_1', 'images/EmailMe_Layer-1-over.gi
      f');return true;"
      onmouseout="cha ngeImagesX('Ema ilMe_Layer_1',' images/EmailMe_Layer-1.gif');re
      turn true;">
      <img name="EmailMe_L ayer_1"
      src="images/EmailMe_Layer-1.gif"
      border="0"
      width="140"
      height="25"></A>

      The test page is still at www.pgacon.com/testpage.htm

      Any other ideas? Thanks-

      --
      Peter Aitken

      Remove the crap from my email address before using.


      Comment

      • Richard Cornford

        #4
        Re: Open new window with JS

        Peter Aitken wrote:[color=blue]
        > Lee wrote:[/color]
        <snip>[color=blue]
        > <a href="email_me. htm"
        >[/color]
        onclick="window .open('email_me .htm','validNam e','height=260, width=400);
        ^ ^
        Error: unterminated string constant.
        [color=blue]
        >return false;"[/color]
        <snip>[color=blue]
        > Any other ideas?[/color]

        Read (and understand) the error messages that the browser generates.

        Richard.


        Comment

        • Lee

          #5
          Re: Open new window with JS

          Peter Aitken said:
          [color=blue]
          >Thanks for the info, Lee - it helped but it is still not right - the new
          >page opens in the original browser window instead of a new window. Here's
          >the code:
          >
          ><a href="email_me. htm"
          >onclick="windo w.open('email_m e.htm','validNa me','height=260 ,width=400);ret ur
          >n false;"
          >onmouseover="c hangeImagesX('E mailMe_Layer_1' ,'images/EmailMe_Layer-1-over.gi
          >f');return true;"
          >onmouseout="ch angeImagesX('Em ailMe_Layer_1', 'images/EmailMe_Layer-1.gif');re
          >turn true;">
          ><img name="EmailMe_L ayer_1"
          > src="images/EmailMe_Layer-1.gif"
          > border="0"
          > width="140"
          > height="25"></A>
          >[/color]

          I made a typo that causes the window.open() call to fail, which
          causes the "return false" to never be executed, allowing the
          link to be followed, opening the page in the current window.

          There should be a closing single-quote after the window attributes:

          window.open('em ail_me.htm','va lidName','heigh t=260,width=400 ');returen false

          Comment

          • Peter Aitken

            #6
            Re: Open new window with JS

            "Richard Cornford" <Richard@litote s.demon.co.uk> wrote in message
            news:cbv8ni$d1r $1$830fa79d@new s.demon.co.uk.. .[color=blue]
            > Peter Aitken wrote:[color=green]
            > > Lee wrote:[/color]
            > <snip>[color=green]
            > > <a href="email_me. htm"
            > >[/color]
            > onclick="window .open('email_me .htm','validNam e','height=260, width=400);
            > ^ ^
            > Error: unterminated string constant.
            >[color=green]
            > >return false;"[/color]
            > <snip>[color=green]
            > > Any other ideas?[/color]
            >
            > Read (and understand) the error messages that the browser generates.
            >
            > Richard.
            >
            >[/color]

            Ah, but it did not generate any error messages! In any event the problem is
            fixed now.


            --
            Peter Aitken

            Remove the crap from my email address before using.


            Comment

            • Peter Aitken

              #7
              Re: Open new window with JS

              "Lee" <REM0VElbspamtr ap@cox.net> wrote in message
              news:cbv8fg0pv6 @drn.newsguy.co m...[color=blue]
              > Peter Aitken said:
              >[color=green]
              > >Thanks for the info, Lee - it helped but it is still not right - the new
              > >page opens in the original browser window instead of a new window. Here's
              > >the code:
              > >
              > ><a href="email_me. htm"[/color]
              >
              >onclick="windo w.open('email_m e.htm','validNa me','height=260 ,width=400);ret u[/color]
              r[color=blue][color=green]
              > >n false;"[/color]
              >
              >onmouseover="c hangeImagesX('E mailMe_Layer_1' ,'images/EmailMe_Layer-1-over.g[/color]
              i[color=blue][color=green]
              > >f');return true;"[/color]
              >
              >onmouseout="ch angeImagesX('Em ailMe_Layer_1', 'images/EmailMe_Layer-1.gif');r[/color]
              e[color=blue][color=green]
              > >turn true;">
              > ><img name="EmailMe_L ayer_1"
              > > src="images/EmailMe_Layer-1.gif"
              > > border="0"
              > > width="140"
              > > height="25"></A>
              > >[/color]
              >
              > I made a typo that causes the window.open() call to fail, which
              > causes the "return false" to never be executed, allowing the
              > link to be followed, opening the page in the current window.
              >
              > There should be a closing single-quote after the window attributes:
              >
              > window.open('em ail_me.htm','va lidName','heigh t=260,width=400 ');returen[/color]
              false[color=blue]
              >[/color]

              Yikes, I should have caught that myself! Thanks a lot - it's been a big
              help.


              --
              Peter Aitken

              Remove the crap from my email address before using.


              Comment

              • Mick White

                #8
                Re: Open new window with JS

                Peter Aitken wrote:

                [color=blue]
                >
                > Ah, but it did not generate any error messages! In any event the problem is
                > fixed now.
                >[/color]

                Yes it did.
                Mick

                Comment

                Working...