stop refresh windows?

Discussion in 'Javascript' started by Baffin Shea, Sep 5, 2003.

  1. Baffin Shea

    Baffin Shea Guest

    Dear All,

    I am a beginner in javascript and looking for help, I put the following
    script in the original.asp:

    function NewWindows()
    {
    window.open("abc.asp", "new")
    }

    Everytime after the script is run, the original.asp will refresh itself and
    the browser will go back to the top, there is something new at the tail of
    url likes original.asp?x=42&y=6, the value of x and y will be different
    every refresh, is it possible to stop the refresh of orignal.asp? Thanks for
    help.
     
    Baffin Shea, Sep 5, 2003
    #1
    1. Advertising

  2. "Baffin Shea" <> writes:

    > Everytime after the script is run, the original.asp will refresh itself and
    > the browser will go back to the top, there is something new at the tail of
    > url likes original.asp?x=42&y=6, the value of x and y will be different
    > every refresh, is it possible to stop the refresh of orignal.asp?


    It is not the function you showed us that refreshes the original.asp
    page. It is most likely the method you use to call it.

    My guess is that you have something like:
    <input type="image" src="..." onclick="NewWindows()">
    or perhaps the call to NewWindows is inside an image map.

    In any case, you should stop the click that activate NewWindows from
    having its normal effect. You do that by adding a "return false"
    at the end of the onclick attribute:
    onclick="NewWindows();return false;"

    /L
    --
    Lasse Reichstein Nielsen -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Sep 5, 2003
    #2
    1. Advertising

  3. "Baffin Shea" <> wrote in message
    news:3f584f60$...
    >I am a beginner in javascript and looking for help,


    OK, save yourself from making the error of producing unreliable scripts
    by never attempting to open a new window from a web browser. It may look
    easy, you may see it consistently working in your controlled and
    predictable test environment and there may even be thousands of examples
    and instances of other people attempting it, but on the Internet the
    outcome of that simple call to - window.open - is so unpredictable as to
    make any planned design that involves the attempt impractical.

    >I put the following script in the original.asp:
    >
    > function NewWindows()
    > {
    > window.open("abc.asp", "new")
    > }
    >
    >Everytime after the script is run, the original.asp will refresh
    >itself and the browser will go back to the top, there is something
    >new at the tail of url likes original.asp?x=42&y=6, the value of x
    >and y will be different every refresh, is it possible to stop the
    >refresh of orignal.asp? Thanks for help.


    There is nothing about the - window.open - function (assuming that it is
    implemented on the browser and has not been replaced by a content
    inserting/re-writing proxy) that would induce a re-load of the current
    page. The problem is probably connected with how this function is
    called. My guess (because of the query string) is that you have a
    failure to cancel the default action in a form that is calling this
    function in its onsubmit handler or from an event connected with one
    type of submit button (be it <input type="submit">, <input type="image">
    or <button>).

    Without seeing how the function is called it is impossible to say.

    Richard.
     
    Richard Cornford, Sep 5, 2003
    #3
  4. Baffin Shea

    Baffin Shea Guest

    Dear Lasse,

    Thank you for you help. However, you method will work only in the preview of
    ms-frontpage, it doesn't work anymore after upload the .asp to the server
    and browse it using IE, any suggestion?

    Baffin


    "Lasse Reichstein Nielsen" <>
    ???????:...
    > "Baffin Shea" <> writes:
    >
    > > Everytime after the script is run, the original.asp will refresh itself

    and
    > > the browser will go back to the top, there is something new at the tail

    of
    > > url likes original.asp?x=42&y=6, the value of x and y will be different
    > > every refresh, is it possible to stop the refresh of orignal.asp?

    >
    > It is not the function you showed us that refreshes the original.asp
    > page. It is most likely the method you use to call it.
    >
    > My guess is that you have something like:
    > <input type="image" src="..." onclick="NewWindows()">
    > or perhaps the call to NewWindows is inside an image map.
    >
    > In any case, you should stop the click that activate NewWindows from
    > having its normal effect. You do that by adding a "return false"
    > at the end of the onclick attribute:
    > onclick="NewWindows();return false;"
    >
    > /L
    > --
    > Lasse Reichstein Nielsen -
    > Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    > 'Faith without judgement merely degrades the spirit divine.'
     
    Baffin Shea, Sep 5, 2003
    #4
  5. Baffin Shea

    Baffin Shea Guest

    Dear Richard,

    Thanks for your reply, I call the function like this:

    <head>
    :
    :
    <script language=javascript>
    function NewWindow()
    {
    window.open("abc.asp", "new")
    }
    :
    :
    </script>
    </head>

    <body>
    :
    :
    <form>
    <input type=image src="cde.gif" onclick="NewWindow()">
    </form>
    :
    :
    </body>

    Do you have any idea. Thank you.

    Regards,
    Baffin


    "Richard Cornford" <> ¼¶¼g©ó¶l¥ó·s»D
    :bj9o0j$c74$1$...
    > "Baffin Shea" <> wrote in message
    > news:3f584f60$...
    > >I am a beginner in javascript and looking for help,

    >
    > OK, save yourself from making the error of producing unreliable scripts
    > by never attempting to open a new window from a web browser. It may look
    > easy, you may see it consistently working in your controlled and
    > predictable test environment and there may even be thousands of examples
    > and instances of other people attempting it, but on the Internet the
    > outcome of that simple call to - window.open - is so unpredictable as to
    > make any planned design that involves the attempt impractical.
    >
    > >I put the following script in the original.asp:
    > >
    > > function NewWindows()
    > > {
    > > window.open("abc.asp", "new")
    > > }
    > >
    > >Everytime after the script is run, the original.asp will refresh
    > >itself and the browser will go back to the top, there is something
    > >new at the tail of url likes original.asp?x=42&y=6, the value of x
    > >and y will be different every refresh, is it possible to stop the
    > >refresh of orignal.asp? Thanks for help.

    >
    > There is nothing about the - window.open - function (assuming that it is
    > implemented on the browser and has not been replaced by a content
    > inserting/re-writing proxy) that would induce a re-load of the current
    > page. The problem is probably connected with how this function is
    > called. My guess (because of the query string) is that you have a
    > failure to cancel the default action in a form that is calling this
    > function in its onsubmit handler or from an event connected with one
    > type of submit button (be it <input type="submit">, <input type="image">
    > or <button>).
    >
    > Without seeing how the function is called it is impossible to say.
    >
    > Richard.
    >
    >
     
    Baffin Shea, Sep 5, 2003
    #5
  6. "Baffin Shea" <> wrote in message
    news:3f58aa99$...
    <snip>
    ><form>
    > <input type=image src="cde.gif" onclick="NewWindow()">
    ></form>

    <snip>
    >Do you have any idea. Thank you.

    <snip>

    As Lasse and I suspected, the problem is the failure to cancel the
    default action on he input element (which is to submit the form to the
    URL specified in the (missing) action attribute of the form element).
    And Lasse's suggestion of adding - return false; - to the onclick
    handler will cancel that action in all of the browsers that support the
    onclick event on <input type="image"> elements. Wider support can be
    achieved by providing the FORM element with an onsubmit handler that
    cancels the submit by returning false.

    I still think it would be better to abandon the window opening idea
    entirely but, given what the script does now, it is possible to achieve
    exactly the same effect with pure HTML (and if something can be done
    with HTML instead of JavaScript it should be done with HTML). If the
    FORM element specified "abc.asp" as its ACTION attribute and had a
    TARGET attribute of "_blank" you cold forget the script entirely and
    achieve the same result:-


    <form action="abc.asp" name="fName" target="_blank">
    <input type=image src="cde.gif" alt="???">
    </form>

    One of the advantages of a pure HTML approach to opening new window is
    that it reduces the number of possible outcomes when the user clicks the
    button down to four. And it is much easier to design a workable UI if a
    user action only results in any one of four unpredictable consequences.
    One would be ideal but it is still and improvement on the six or seven
    possible outcomes of the JavaScript based attempt.

    Richard.
     
    Richard Cornford, Sep 5, 2003
    #6
  7. Baffin Shea

    Baffin Shea Guest

    Dear Richard,

    In fact, I designed using html instead of javascript, it's much more easier.
    But a new window will be popup everytime if the button have been clicked.
    What I want to do is a new window will be popup in the first time clicking
    on the button, and then the window will only be updated and refreshed when
    the second time the button to be clicked.

    The javascript can do the work:
    window.open("abc.asp", "new")

    Can it be replaced by the html? If so, then everytime is easier.

    p/s: I tried the Lasse's method, it works in Frontpage environment, but
    doesn't work after uploading the file in the server.

    Thank you.

    Regards,
    Baffin




    "Richard Cornford" <> ¼¶¼g©ó¶l¥ó·s»D
    :bjb1l8$b5l$1$...
    > "Baffin Shea" <> wrote in message
    > news:3f58aa99$...
    > <snip>
    > ><form>
    > > <input type=image src="cde.gif" onclick="NewWindow()">
    > ></form>

    > <snip>
    > >Do you have any idea. Thank you.

    > <snip>
    >
    > As Lasse and I suspected, the problem is the failure to cancel the
    > default action on he input element (which is to submit the form to the
    > URL specified in the (missing) action attribute of the form element).
    > And Lasse's suggestion of adding - return false; - to the onclick
    > handler will cancel that action in all of the browsers that support the
    > onclick event on <input type="image"> elements. Wider support can be
    > achieved by providing the FORM element with an onsubmit handler that
    > cancels the submit by returning false.
    >
    > I still think it would be better to abandon the window opening idea
    > entirely but, given what the script does now, it is possible to achieve
    > exactly the same effect with pure HTML (and if something can be done
    > with HTML instead of JavaScript it should be done with HTML). If the
    > FORM element specified "abc.asp" as its ACTION attribute and had a
    > TARGET attribute of "_blank" you cold forget the script entirely and
    > achieve the same result:-
    >
    >
    > <form action="abc.asp" name="fName" target="_blank">
    > <input type=image src="cde.gif" alt="???">
    > </form>
    >
    > One of the advantages of a pure HTML approach to opening new window is
    > that it reduces the number of possible outcomes when the user clicks the
    > button down to four. And it is much easier to design a workable UI if a
    > user action only results in any one of four unpredictable consequences.
    > One would be ideal but it is still and improvement on the six or seven
    > possible outcomes of the JavaScript based attempt.
    >
    > Richard.
    >
    >
     
    Baffin Shea, Sep 6, 2003
    #7
    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. Matt Theule

    Stop Debugging doesn't stop in ASP.NET

    Matt Theule, Jul 23, 2003, in forum: ASP .Net
    Replies:
    7
    Views:
    736
    Matt Theule
    Jul 24, 2003
  2. =?Utf-8?B?Q2VzYXJfQ2FzdGlsbG8=?=

    Stop the refresh in WebPages

    =?Utf-8?B?Q2VzYXJfQ2FzdGlsbG8=?=, Dec 22, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    389
    =?Utf-8?B?UmFodWwgU29uaQ==?=
    Dec 22, 2005
  3. Son KwonNam
    Replies:
    11
    Views:
    2,605
    mr_organic
    Apr 9, 2004
  4. Will
    Replies:
    1
    Views:
    15,246
    Thomas Weidenfeller
    Nov 2, 2004
  5. Angus
    Replies:
    5
    Views:
    453
    Ben Bacarisse
    Jul 18, 2010
Loading...

Share This Page