New URL on the same window

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

    New URL on the same window

    I have a confirmation page with an OK button. If this window has an
    opener then this browser window needs to go to another URL or else the
    window must close.

    Thus I have the following javascript to achieve the above which does
    not work:
    <script language="jscri pt">
    function PageRedirection ()
    {
    if(!opener)
    {
    //document.url("S earch.aspx");
    //location.replac e("Search.aspx" );
    window.location .href = "Search.asp x";
    }
    else
    {
    window.close();
    }
    }
    </script>
    Can someone help???
    Thanks in advance
  • Lee

    #2
    Re: New URL on the same window

    Renuka said:[color=blue]
    >
    >I have a confirmation page with an OK button. If this window has an
    >opener then this browser window needs to go to another URL or else the
    >window must close.
    >
    >Thus I have the following javascript to achieve the above which does
    >not work:
    ><script language="jscri pt">
    >function PageRedirection ()
    >{
    > if(!opener)
    > {
    > //document.url("S earch.aspx");
    > //location.replac e("Search.aspx" );
    > window.location .href = "Search.asp x";
    > }
    > else
    > {
    > window.close();
    > }
    > }
    ></script>
    >Can someone help???[/color]

    What does "does not work" mean, precisely?
    With the <script> tag corrected to:
    <script type="text/javascript">
    it works fine for me in several browsers.

    Comment

    • Renuka Srivastava

      #3
      Re: New URL on the same window

      The new URL which should open on th esame window does not work , to be
      precise this exact line does not work:


      window.location .href = "Search.asp x";

      What works is the window.close() method.

      Thanks
      Renuka




      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Lee

        #4
        Re: New URL on the same window

        Renuka Srivastava said:[color=blue]
        >
        >The new URL which should open on th esame window does not work , to be
        >precise this exact line does not work:
        >
        >
        >window.locatio n.href = "Search.asp x";
        >
        >What works is the window.close() method.[/color]

        That still doesn't tell me what you mean by "does not work".
        Are there any error messages? Does it do nothing at all, or
        does it seem to do the wrong thing?

        Comment

        • Renuka Srivastava

          #5
          Re: New URL on the same window

          I have a Confirmation.as px page with an "OK" button. Once that button is
          clicked it instantiates the javascript function on the clientside. If
          this Confirmation.as px has an opener the "OK" button should close the
          browser window(which works properly), but when there is no opener the
          "OK" button should open a different URL on the same window instead it
          remains on the page Confirmation.as px

          window.location .href = "Search.asp x";

          Hope I have made myself clear

          *** Sent via Developersdex http://www.developersdex.com ***
          Don't just participate in USENET...get rewarded for it!

          Comment

          • Lee

            #6
            Re: New URL on the same window

            Renuka Srivastava said:[color=blue]
            >
            >I have a Confirmation.as px page with an "OK" button. Once that button is
            >clicked it instantiates the javascript function on the clientside. If
            >this Confirmation.as px has an opener the "OK" button should close the
            >browser window(which works properly), but when there is no opener the
            >"OK" button should open a different URL on the same window instead it
            >remains on the page Confirmation.as px
            >
            >window.locatio n.href = "Search.asp x";
            >
            >Hope I have made myself clear[/color]

            My best guess is that "Search.asp x" is not found.
            Try specifying the complete URL.
            Your code as written works just fine, if the specified URL exists.

            Comment

            • Michael Winter

              #7
              Re: New URL on the same window

              Renuka wrote on 09 Dec 2003 at Tue, 09 Dec 2003 16:38:22 GMT:
              [color=blue]
              > I have a confirmation page with an OK button. If this window has
              > an opener then this browser window needs to go to another URL or
              > else the window must close.
              >
              > Thus I have the following javascript to achieve the above which
              > does not work:
              > <script language="jscri pt">[/color]

              You must use the type attribute: it is required by the HTML
              specification. The language attribute is then usually not needed. The
              above should read (assuming you're using JScript, and not
              JavaScript):

              <script type="text/jscript">
              [color=blue]
              > function PageRedirection ()
              > {
              > if(!opener)
              > {
              > //document.url("S earch.aspx");
              > //location.replac e("Search.aspx" );
              > window.location .href = "Search.asp x";
              > }
              > else
              > {
              > window.close();
              > }
              > }
              > </script>[/color]

              Simple: remove the exclamation mark (!). Think about it...

              A call to window.open() opens a new window (child), and sets the
              window.opener property of the child to reference the parent's window
              object (hope that made sense) [1]. If a window wasn't opened with a
              window.open() call, window.opener is undefined or null (depending on
              the browser). The former evaluates to true as a boolean, and the
              latter as false:

              if ( window.opener ) {
              // Window opened with window.open()
              } else {
              // Window opened by some other means
              }

              What you have in your post is reversed, so when window.opener
              references a window object, it closes the window rather than
              redirecting it.

              On a different note: I would advise that you fully qualify the opener
              property. That is, use window.opener, not just opener.

              Mike


              [1] The first part of that sentence is /very/ important: the
              window.opener property is set when window.open() is used to create
              the window.

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

              Comment

              • Lee

                #8
                Re: New URL on the same window

                Michael Winter said:[color=blue]
                >
                >What you have in your post is reversed, so when window.opener
                >references a window object, it closes the window rather than
                >redirecting it.[/color]

                Why do you assume that this isn't what the OP wants?
                If this is not a child window, redirect to the new location.
                If this is a child window, close it.

                Comment

                • Michael Winter

                  #9
                  Re: New URL on the same window

                  Lee wrote on 10 Dec 2003 at Wed, 10 Dec 2003 01:00:42 GMT:
                  [color=blue]
                  > Michael Winter said:[color=green]
                  >>
                  >> What you have in your post is reversed, so when window.opener
                  >> references a window object, it closes the window rather than
                  >> redirecting it.[/color]
                  >
                  > Why do you assume that this isn't what the OP wants? If this is
                  > not a child window, redirect to the new location. If this is a
                  > child window, close it.[/color]

                  Umm, perhaps because the OP said that a child window (i.e.
                  non-null window.opener) should be redirected, whilst a window with
                  a null window.opener should be closed.

                  From the original post:
                  [color=blue]
                  > I have a confirmation page with an OK button. If this window has
                  > an opener then this browser window needs to go to another URL or
                  > else the window must close.[/color]

                  Mike

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

                  Comment

                  Working...