window.location and opera

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

    window.location and opera

    hi guys,

    this code works fine in IE but doesnot work in opera. the page just
    reloads to test.html# in opera.

    can anyone help? thanks.

    -----------------------------------------------------------------------

    <html>
    <head><script language="JavaS cript" type="text/JavaScript">
    function disco() {
    if( confirm('are you sure?') ) {
    window.location ="http://wwww.google.com ";
    }
    }
    </script>
    </head>
    <body>
    <a href="#" onClick="javasc ript:disco()">D &eacute;connexi on</a></body>
    </html>
  • Ivo

    #2
    Re: window.location and opera

    "K. S." wrote[color=blue]
    > this code works fine in IE but doesnot work in opera. the page just
    > reloads to test.html# in opera.
    >
    > <html>
    > <head><script language="JavaS cript" type="text/JavaScript">
    > function disco() {
    > if( confirm('are you sure?') ) {
    > window.location ="http://wwww.google.com ";[/color]

    Try setting the location's href property directly:
    window.location .href="http://wwww.google.com ";
    [color=blue]
    > }
    > }
    > </script>
    > </head>
    > <body>
    > <a href="#" onClick="javasc ript:disco()">D &eacute;connexi on</a>[/color]

    onclick="disco( );"

    without the "javascript :" bit and preferably with an ending semicolon for
    good manners.
    [color=blue]
    > </body></html>[/color]

    I don't have opera but it 's always the same little things..
    HTH
    Ivo


    Comment

    • Randy Webb

      #3
      Re: window.location and opera

      K. S. wrote:[color=blue]
      > hi guys,
      >
      > this code works fine in IE but doesnot work in opera. the page just
      > reloads to test.html# in opera.
      >
      > can anyone help? thanks.
      >
      > -----------------------------------------------------------------------
      >
      > <html>
      > <head><script language="JavaS cript" type="text/JavaScript">
      > function disco() {
      > if( confirm('are you sure?') ) {
      > window.location ="http://wwww.google.com ";
      > }
      > }
      > </script>
      > </head>
      > <body>
      > <a href="#" onClick="javasc ript:disco()">D &eacute;connexi on</a></body>
      > </html>[/color]

      Probably because you are not returning false from the onclick. Also, you
      do not need the javascript: and that may also be part of Opera not
      working with it:

      <a href="noScript. html" onclick="disco( );return false">........ .</a>

      Comment

      • Mick White

        #4
        Re: window.location and opera

        K. S. wrote:
        [color=blue]
        > hi guys,
        >
        > this code works fine in IE but doesnot work in opera. the page just
        > reloads to test.html# in opera.
        >
        > can anyone help? thanks.
        >
        > -----------------------------------------------------------------------
        >
        > <html>
        > <head><script language="JavaS cript" type="text/JavaScript">
        > function disco() {
        > if( confirm('are you sure?') )[/color]

        window.confirm method requires two arguments

        function disco(){
        if(confirm('are you sure?','') ){.....

        Mick

        {[color=blue]
        > window.location ="http://wwww.google.com ";
        > }
        > }
        > </script>
        > </head>
        > <body>
        > <a href="#" onClick="javasc ript:disco()">D &eacute;connexi on</a></body>
        > </html>[/color]

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: window.location and opera

          K. S. wrote:[color=blue]
          > this code works fine in IE but doesnot work in opera. the page just
          > reloads to test.html# in opera.
          >
          > can anyone help? thanks.[/color]

          Make it Valid HTML[1] first, and remove the "javascript :" nonsense,
          see the FAQ[2].


          PointedEars
          ___________
          [1] <http://validator.w3.or g/>
          [2] <http://jibbering.com/faq/>

          Comment

          • Lee

            #6
            Re: window.location and opera

            K. S. said:[color=blue]
            >
            >hi guys,
            >
            >this code works fine in IE but doesnot work in opera. the page just
            >reloads to test.html# in opera.
            >
            >can anyone help? thanks.
            >
            >-----------------------------------------------------------------------
            >
            ><html>
            > <head><script language="JavaS cript" type="text/JavaScript">
            > function disco() {
            > if( confirm('are you sure?') ) {
            > window.location ="http://wwww.google.com ";
            > }
            > }
            ></script>
            > </head>
            ><body>
            ><a href="#" onClick="javasc ript:disco()">D &eacute;connexi on</a></body>
            ></html>[/color]


            Since your onClick event handler does not return false, you're
            telling the page to both:
            a) set the location to google.com
            b) follow the URL specified in the HREF value to "test.html# "

            Browsers will do one or the other. Since following the link is
            the primary function of the <A> tag, that's what most browsers
            will do. If that's not what you want, return false:

            onclick="disco( );return false"




            Comment

            • Grant Wagner

              #7
              Re: window.location and opera

              Mick White wrote:
              [color=blue]
              > K. S. wrote:
              >[color=green]
              > > hi guys,
              > >
              > > this code works fine in IE but doesnot work in opera. the page just
              > > reloads to test.html# in opera.
              > >
              > > can anyone help? thanks.
              > >
              > > -----------------------------------------------------------------------
              > >
              > > <html>
              > > <head><script language="JavaS cript" type="text/JavaScript">
              > > function disco() {
              > > if( confirm('are you sure?') )[/color]
              >
              > window.confirm method requires two arguments
              >
              > function disco(){
              > if(confirm('are you sure?','') ){.....[/color]

              No, it really doesn't: <url:

              />

              It actually doesn't even require one argument in Internet Explorer: <url:
              Learn with interactive lessons and technical documentation, earn professional development hours and certifications, and connect with the community.

              />

              Although Gecko-based browsers generate an error and Netscape 4 presents a
              confirm dialog that says "undefined" if you attempt to call confirm() without
              any arguments. Regardless, that wasn't his problem. He explicitly said that
              the link "reloads <the url>#". This is a major hint that he's got the
              following code:
              [color=blue][color=green]
              > > <a href="#" onClick="javasc ript:disco()">D &eacute;connexi on</a></body>[/color][/color]

              and that he isn't returning false from the onclick event:

              <a href="#" onclick="disco( );return false;">Google</a>

              Of course, this isn't really what he wants because regardless of what the
              user chooses the link won't be followed. What he wants is for the link to
              force the user to answer yes or no, so:

              <script type="text/javascript">
              function disco() {
              return confirm("Are you sure?");
              }
              </script>
              <a href="http://wwww.google.com " onclick="return disco();">Googl e</a>

              Is what he really wants.

              Now you've got a fully functional link regardless of whether the browser
              supports or has JavaScript enabled. And if JavaScript is enabled, it will
              prompt the user "Are you sure?". Clicking the affirmative button will result
              in true being returned to the event and the HREF will be followed. Clicking
              the negative button will result in false being returned to the event and the
              HREF will not be followed.

              --
              Grant Wagner <gwagner@agrico reunited.com>
              comp.lang.javas cript FAQ - http://jibbering.com/faq

              Comment

              • Mick White

                #8
                Re: window.location and opera

                Grant Wagner wrote:
                [color=blue]
                > Mick White wrote:[/color]
                [color=blue][color=green]
                >>window.confir m method requires two arguments[/color][/color]
                [color=blue]
                > No, it really doesn't: <url:
                > http://devedge.netscape.com/library/...w.html#1201914
                > />
                >
                > It actually doesn't even require one argument in Internet Explorer: <url:
                > http://msdn.microsoft.com/workshop/a...ds/confirm.asp
                > />[/color]

                Well, "require" is probably the wrong word, "recommende d" would be more
                accurate.
                [color=blue]
                > Although Gecko-based browsers generate an error and Netscape 4 presents a
                > confirm dialog that says "undefined" if you attempt to call confirm() without
                > any arguments. Regardless, that wasn't his problem. He explicitly said that
                > the link "reloads <the url>#".[/color]

                The answer to this problem was already pointed out to the OP.

                Mick

                Comment

                • K. S.

                  #9
                  Re: window.location and opera

                  Thanks all ...

                  Lee's post was the one that made it work.

                  for reference, here is the code that works:

                  ----------------------------------------------------------------------
                  <html>
                  <head><script language="JavaS cript" type="text/JavaScript">
                  function disco() {
                  if( confirm('are you sure?','') ) {
                  window.location .href="http://www.google.com" ;
                  }
                  }
                  </script>
                  </head>
                  <body>
                  <a href="#" onClick="disco( );return false;">D&eacut e;connexion</a></body>
                  </html>


                  Lee <REM0VElbspamtr ap@cox.net> wrote in message news:<ce76am0qt g@drn.newsguy.c om>...[color=blue]
                  > K. S. said:[color=green]
                  > >
                  > >hi guys,
                  > >
                  > >this code works fine in IE but doesnot work in opera. the page just
                  > >reloads to test.html# in opera.
                  > >
                  > >can anyone help? thanks.
                  > >
                  > >-----------------------------------------------------------------------
                  > >
                  > ><html>
                  > > <head><script language="JavaS cript" type="text/JavaScript">
                  > > function disco() {
                  > > if( confirm('are you sure?') ) {
                  > > window.location ="http://wwww.google.com ";
                  > > }
                  > > }
                  > ></script>
                  > > </head>
                  > ><body>
                  > ><a href="#" onClick="javasc ript:disco()">D &eacute;connexi on</a></body>
                  > ></html>[/color]
                  >
                  >
                  > Since your onClick event handler does not return false, you're
                  > telling the page to both:
                  > a) set the location to google.com
                  > b) follow the URL specified in the HREF value to "test.html# "
                  >
                  > Browsers will do one or the other. Since following the link is
                  > the primary function of the <A> tag, that's what most browsers
                  > will do. If that's not what you want, return false:
                  >
                  > onclick="disco( );return false"[/color]

                  Comment

                  • Grant Wagner

                    #10
                    Re: window.location and opera

                    Mick White wrote:
                    [color=blue]
                    > Grant Wagner wrote:
                    >[color=green]
                    > > Mick White wrote:[/color]
                    >[color=green][color=darkred]
                    > >>window.confir m method requires two arguments[/color][/color]
                    >[color=green]
                    > > No, it really doesn't: <url:
                    > > http://devedge.netscape.com/library/...w.html#1201914
                    > > />
                    > >
                    > > It actually doesn't even require one argument in Internet Explorer: <url:
                    > > http://msdn.microsoft.com/workshop/a...ds/confirm.asp
                    > > />[/color]
                    >
                    > Well, "require" is probably the wrong word, "recommende d" would be more
                    > accurate.[/color]

                    Well, no, a second parameter for the confirm() method isn't "recommende d" either. In both of the
                    links shown above confirm() takes exactly one parameter (well, in the case of IE, even that one
                    parameter is optional). The Gecko DOM is the same: <url:
                    http://www.mozilla.org/docs/dom/domr...2.html#1016997 />

                    Oh, it just occurred to me, you're thinking of prompt(), which does take a second (optional)
                    parameter.

                    --
                    Grant Wagner <gwagner@agrico reunited.com>
                    comp.lang.javas cript FAQ - http://jibbering.com/faq

                    Comment

                    • Mick White

                      #11
                      Re: window.location and opera

                      Grant Wagner wrote:

                      [color=blue]
                      >
                      > Oh, it just occurred to me, you're thinking of prompt(), which does take a second (optional)
                      > parameter.[/color]

                      By golly, you're right, I am. Sorry to the OP for the confusion.
                      Mick

                      [color=blue]
                      > Grant Wagner <gwagner@agrico reunited.com>
                      > comp.lang.javas cript FAQ - http://jibbering.com/faq
                      >[/color]

                      Comment

                      Working...