open new window

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

    open new window

    Hi,

    I have this code in the head of the page:

    script language="JavaS cript" type="text/JavaScript">
    <!--

    function goTo(targ,selOb j,restore){ //v3.0
    eval(targ+".loc ation='"+selObj .options[selObj.selected Index].value+"'");
    if (restore) selObj.selected Index=0;
    }
    //-->
    </script>

    and this bit in the body section:

    <form name="form1" method="post" action="">
    <select name="select" onChange="goTo( 'self',this,0)" >

    Simple put I want the new page to open in a new window, I assumed that
    changing the 'self' bit to 'blank' would work but all I get are JavaScript
    undefined error messages.

    Does anybody have any other ideas as to what I could try ?

    Thanks



  • Lasse Reichstein Nielsen

    #2
    Re: open new window

    "Andy" <andyww14@hotma il.com> writes:
    [color=blue]
    >
    > script language="JavaS cript" type="text/JavaScript">[/color]

    The language attribute is deprecated and can safely be omitted
    [color=blue]
    > <!--[/color]

    This HTML comment starter can also safely be omitted.
    [color=blue]
    >
    > function goTo(targ,selOb j,restore){ //v3.0
    > eval(targ+".loc ation='"+selObj .options[selObj.selected Index].value+"'");[/color]

    Yikes. Bad use of eval. You will probably never need to use eval, as
    there are better alternatives.

    Just use:
    function goTo(tObj,selOb j,restore) {
    tObj.location=s elObj.options[selObj.selected Index].value;
    ...
    and
    [color=blue]
    > <form name="form1" method="post" action="">
    > <select name="select" onChange="goTo( 'self',this,0)" >[/color]

    onchange="goTo( self,this,false );"

    [color=blue]
    > Simple put I want the new page to open in a new window, I assumed that
    > changing the 'self' bit to 'blank' would work but all I get are JavaScript
    > undefined error messages.[/color]

    This code is only built to open in existing windows.
    [color=blue]
    > Does anybody have any other ideas as to what I could try ?[/color]

    function goToNew(winName ,selObj,restore ) {
    var win = window.open(sel Obj.options[selObj.selected Index],winName);
    if (restore) {selObj.selecte dIndex=0;}
    return win;
    }

    called as, e.g.:
    onchange="goToN ew('_blank',thi s,false);"

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Michael Winter

      #3
      Re: open new window

      On Sat, 17 Apr 2004 20:42:42 +0100, Andy <andyww14@hotma il.com> wrote:
      [color=blue]
      > I have this code in the head of the page:
      >
      > script language="JavaS cript" type="text/JavaScript">[/color]

      The language attribute is deprecated, and the presence of the type
      attribute makes it redundant. Remove it.
      [color=blue]
      > <!--[/color]

      Script hiding is a practice that is now obsolete. Remove the SGML comment
      delimiters.
      [color=blue]
      > function goTo(targ,selOb j,restore){ //v3.0
      > eval(targ+".loc ation='"+selObj .options[selObj.selected Index].value+"'");[/color]

      Why are you using eval()? I don't see why you can't just make targ an
      object reference and then write:

      targ.location.h ref = selObj.options[ selObj.selected Index ].value;

      Notice that there is no need to convert the value property to a string.
      The form control values are *always* returned as strings.
      [color=blue]
      > if (restore) selObj.selected Index=0;
      > }
      > //-->[/color]

      Remove this delimiter along with the first.
      [color=blue]
      > </script>
      >
      > and this bit in the body section:
      >
      > <form name="form1" method="post" action="">
      > <select name="select" onChange="goTo( 'self',this,0)" >[/color]

      To work with the changes above, change the call to

      goTo(self,this, false)

      I changed the last argument to false because it makes more sense to pass
      booleans when evaluating booleans.
      [color=blue]
      > Simple put I want the new page to open in a new window, I assumed that
      > changing the 'self' bit to 'blank' would work but all I get are
      > JavaScript undefined error messages.[/color]

      That's because "self" is an object reference to the current window
      (equivalent to window.self or window), whereas "blank" isn't defined at
      all.
      [color=blue]
      > Does anybody have any other ideas as to what I could try ?[/color]

      A call to window.open(), perhaps?

      Two things to note:

      1) Don't perform navigation actions on the "change" event.
      2) Avoid new windows completely, if possible.

      If I use my mouse wheel to change the value, the event will fire every
      time even though I probably haven't chosen a destination yet. Similarly,
      if I make a mistake when choosing a value, I will not get an opportunity
      (unless I'm very quick) to correct it. Use a button instead.

      Mike

      --
      Michael Winter
      M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

      Comment

      Working...