onclick="alert('hello');return false;" does not work in IE7?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • alvin.yk@gmail.com

    onclick="alert('hello');return false;" does not work in IE7?

    Hi,

    Normally, a piece of code such as

    <a href="http://www.yahoo.com" onclick="alert( 'hello');return
    false;">link</a>

    will stop the browser from actually going to href's destination.
    However, this is not the case with the IE7 I am using. What has
    changed?

    IE7 version: 7.0.5730.11. Update versions: 0

    Has anyone bumped into this problem before? How do I get around it?
    Thanks.


    Testcase:
    -----------------------

    <html>

    <body>
    <phello1 </p>
    <a href = 'http://www.yahoo.com' onclick="alert( 'clicked');retu rn
    false;">my test link</a>
    </body>
    </html>

  • Duncan Booth

    #2
    Re: onclick=&quot;a lert('hello');r eturn false;&quot; does not work in IE7?

    alvin.yk@gmail. com wrote:
    Hi,
    >
    Normally, a piece of code such as
    >
    ><a href="http://www.yahoo.com" onclick="alert( 'hello');return
    false;">link</a>
    >
    will stop the browser from actually going to href's destination.
    However, this is not the case with the IE7 I am using. What has
    changed?
    >
    You have a newline after 'return', so javascript will insert a semicolon
    before 'false'. Try taking out the newline and it works fine.

    Comment

    • RobG

      #3
      Re: onclick=&quot;a lert('hello');r eturn false;&quot; does not work in IE7?


      alvin.yk@gmail. com wrote:
      Hi,
      >
      Normally, a piece of code such as
      >
      <a href="http://www.yahoo.com" onclick="alert( 'hello');return
      false;">link</a>
      >
      will stop the browser from actually going to href's destination.
      However, this is not the case with the IE7 I am using. What has
      changed?
      >
      [...]
      Testcase:
      -----------------------
      >
      <html>
      >
      <body>
      <phello1 </p>
      <a href = 'http://www.yahoo.com' onclick="alert( 'clicked');retu rn
      false;">my test link</a>
      </body>
      </html>
      The HTML is invalid, an A element must be inside a block element. I'm
      amost certain that has nothing to do with it, particularly where IE is
      concerned, but you never know! ;-)

      --
      Rob

      Comment

      • Martijn Saly

        #4
        Re: onclick=&quot;a lert('hello');r eturn false;&quot; does not work in IE7?

        RobG wrote:
        alvin.yk@gmail. com wrote:
        >Hi,
        >>
        >Normally, a piece of code such as
        >>
        ><a href="http://www.yahoo.com" onclick="alert( 'hello');return
        >false;">link </a>
        >>
        >will stop the browser from actually going to href's destination.
        >However, this is not the case with the IE7 I am using. What has
        >changed?
        >>
        [...]
        >Testcase:
        >-----------------------
        >>
        ><html>
        >>
        ><body>
        ><phello1 </p>
        ><a href = 'http://www.yahoo.com' onclick="alert( 'clicked');retu rn
        >false;">my test link</a>
        ></body>
        ></html>
        >
        The HTML is invalid, an A element must be inside a block element. I'm
        amost certain that has nothing to do with it, particularly where IE is
        concerned, but you never know! ;-)
        >
        That only goes for XHTML. And since there's no doctype, IE will imply
        HTML4, iirc. I'm with Duncan Booth elsewhere in this thread: the newline
        is the problem.

        --
        Martijn Saly

        Comment

        • alvin.yk@gmail.com

          #5
          Re: onclick=&quot;a lert('hello');r eturn false;&quot; does not work in IE7?


          Hi,

          The newline is just a formatting problem with google. It does not
          exist in the actual code.

          In addition, I tried putting the linking inside <p></p>, but the
          problem is still there.... other suggestions?

          Thanks.


          Martijn Saly wrote:
          RobG wrote:
          alvin.yk@gmail. com wrote:
          Hi,
          >
          Normally, a piece of code such as
          >
          <a href="http://www.yahoo.com" onclick="alert( 'hello');return
          false;">link</a>
          >
          will stop the browser from actually going to href's destination.
          However, this is not the case with the IE7 I am using. What has
          changed?
          >
          [...]
          Testcase:
          -----------------------
          >
          <html>
          >
          <body>
          <phello1 </p>
          <a href = 'http://www.yahoo.com' onclick="alert( 'clicked');retu rn
          false;">my test link</a>
          </body>
          </html>
          The HTML is invalid, an A element must be inside a block element. I'm
          amost certain that has nothing to do with it, particularly where IE is
          concerned, but you never know! ;-)
          >
          That only goes for XHTML. And since there's no doctype, IE will imply
          HTML4, iirc. I'm with Duncan Booth elsewhere in this thread: the newline
          is the problem.
          >
          --
          Martijn Saly

          Comment

          • ASM

            #6
            Re: onclick=&quot;a lert('hello');r eturn false;&quot; does not work in IE7?

            alvin.yk@gmail. com a écrit :
            other suggestions?
            Perhaps you have a tag 'object' or 'embed' or 'applet' in same page ?
            if yes, it is a problem with your Windows !
            I've heard the last update added something blocking popups.

            M$ have then published a medicine
            (something to break the protection they have just created ... ! ! ! !)

            You'ld have to put after last <object ...>

            <script type="text/javascript" src="ieupdate.j s"></script>

            and have this ieupdate.js in same folder.

            file 'ieupdate.js' :
            =============== =====
            objects = document.getEle mentsByTagName( "object");
            for (var i = 0; i < objects.length; i++)
            {
            objects[i].outerHTML = objects[i].outerHTML;
            }

            <http://msdn.microsoft. com/library/default.asp?url =/workshop/author/dhtml/overview/activating_acti vex.asp>

            --
            Stephane Moriaux et son (moins) vieux Mac déjà dépassé
            Stephane Moriaux and his (less) old Mac already out of date

            Comment

            • VK

              #7
              Re: onclick=&quot;a lert('hello');r eturn false;&quot; does not work in IE7?


              ASM wrote:
              Perhaps you have a tag 'object' or 'embed' or 'applet' in same page ?
              if yes, it is a problem with your Windows !
              I've heard the last update added something blocking popups.
              >
              M$ have then published a medicine
              (something to break the protection they have just created ... ! ! ! !)
              >
              You'ld have to put after last <object ...>
              >
              <script type="text/javascript" src="ieupdate.j s"></script>
              >
              and have this ieupdate.js in same folder.
              >
              file 'ieupdate.js' :
              =============== =====
              objects = document.getEle mentsByTagName( "object");
              for (var i = 0; i < objects.length; i++)
              {
              objects[i].outerHTML = objects[i].outerHTML;
              }
              That is the old Eolas workaround, nothing to do with links or popups.
              Eolas' "no activation w/o interaction" block is not IE or Windows
              specific: it is the same for any law-obeyant UA made over the last
              year-and-half. btw this old workaround was contested as legally clean
              because the object tag source code is still coming from the page.
              document.write from external file is the current way (see my "Eolas
              workaround" post)

              Comment

              • VK

                #8
                Re: onclick=&quot;a lert('hello');r eturn false;&quot; does not work in IE7?

                alvin.yk@gmail. com wrote:
                Hi,
                >
                Normally, a piece of code such as
                >
                <a href="http://www.yahoo.com" onclick="alert( 'hello');return
                false;">link</a>
                >
                will stop the browser from actually going to href's destination.
                However, this is not the case with the IE7 I am using. What has
                changed?
                The security, I presume. That must be against the common trick "show
                one URL in status bar, go to another one that mimics it". I guess you
                may turn it off somewhere but you cannot expect it from your visitors.

                If it is what I'm thinking it is, the psi-links of a kind
                <a href="noscript. html" onclick="myFunc tion(); return false;">Select
                all</ais another thing to say bye-bye sooner is better (the first one
                is "holly hack")

                Comment

                • naixn

                  #9
                  Re: onclick=&quot;a lert('hello');r eturn false;&quot; does not work in IE7?

                  alvin.yk@gmail. com wrote :
                  Hi,
                  >
                  Normally, a piece of code such as
                  >
                  <a href="http://www.yahoo.com" onclick="alert( 'hello');return
                  false;">link</a>
                  >
                  will stop the browser from actually going to href's destination.
                  However, this is not the case with the IE7 I am using. What has
                  changed?
                  >
                  IE7 version: 7.0.5730.11. Update versions: 0
                  >
                  Has anyone bumped into this problem before? How do I get around it?
                  Thanks.
                  >
                  >
                  Testcase:
                  -----------------------
                  >
                  <html>
                  >
                  <body>
                  <phello1 </p>
                  <a href = 'http://www.yahoo.com' onclick="alert( 'clicked');retu rn
                  false;">my test link</a>
                  </body>
                  </html>
                  >
                  The problem, I think, is that IE7, at least for A tags, first tries to go
                  to href, and AFTER that, tries to execute onClick actions.
                  In fact :
                  <a href="javascrip t:null()" onClick="alert( 'clicked');"></a>
                  Doesn't work in IE, since null() stops JS.
                  On the other hand, that works:
                  <a href="#" onClick="alert( 'clicked');"></a>

                  I don't know why IE was made this way, since it is absolutely illogical
                  but I do not try to understand M$ anymore now...

                  Juste try to replace href="#" and then, test once again, and tell us :)

                  --
                  Naixn

                  Comment

                  • alvin.yk@gmail.com

                    #10
                    Re: onclick=&quot;a lert('hello');r eturn false;&quot; does not work in IE7?


                    I am not sure what is the problem, but this is the work around I am
                    using now:

                    <a href="javascrip t:;" onclick="foo(); return false;">link</a>

                    Not the best...


                    naixn wrote:
                    alvin.yk@gmail. com wrote :
                    Hi,

                    Normally, a piece of code such as

                    <a href="http://www.yahoo.com" onclick="alert( 'hello');return
                    false;">link</a>

                    will stop the browser from actually going to href's destination.
                    However, this is not the case with the IE7 I am using. What has
                    changed?

                    IE7 version: 7.0.5730.11. Update versions: 0

                    Has anyone bumped into this problem before? How do I get around it?
                    Thanks.


                    Testcase:
                    -----------------------

                    <html>

                    <body>
                    <phello1 </p>
                    <a href = 'http://www.yahoo.com' onclick="alert( 'clicked');retu rn
                    false;">my test link</a>
                    </body>
                    </html>
                    >
                    The problem, I think, is that IE7, at least for A tags, first tries to go
                    to href, and AFTER that, tries to execute onClick actions.
                    In fact :
                    <a href="javascrip t:null()" onClick="alert( 'clicked');"></a>
                    Doesn't work in IE, since null() stops JS.
                    On the other hand, that works:
                    <a href="#" onClick="alert( 'clicked');"></a>
                    >
                    I don't know why IE was made this way, since it is absolutely illogical
                    but I do not try to understand M$ anymore now...
                    >
                    Juste try to replace href="#" and then, test once again, and tell us :)
                    >
                    --
                    Naixn
                    http://fma-fr.net

                    Comment

                    • Richard Cornford

                      #11
                      Re: onclick=&quot;a lert('hello');r eturn false;&quot; does not work in IE7?

                      alvin.yk@gmail. com wrote:
                      Normally, a piece of code such as
                      >
                      <a href="http://www.yahoo.com" onclick="alert( 'hello');
                      return false;">link</a>
                      >
                      will stop the browser from actually going to href's
                      destination. However, this is not the case with the IE7
                      I am using. What has changed?
                      >
                      IE7 version: 7.0.5730.11. Update versions: 0
                      Trying exactly that code (inadvertent line wrapping removed), in exactly
                      that version of IE 7, reveals no issue. The navigation is cancelled as
                      expected.
                      Has anyone bumped into this problem before?
                      Lots of people fail to properly attribute cause and effect relationships
                      when scripting web browsers. An inability to post code that demonstrates
                      the issue if often a symptom of failing to properly attribute its cause
                      and effect relationships.

                      Where you say, "code such as" you probably mean code that consists of a
                      function call followed by a - return false; - statement. It has always
                      been the case that if an exception is thrown in the function call the
                      event handling function stops executing prior to the - return false; -
                      statement and so never returns any value at all to cancel the navigation
                      or not. Thus the navigation happens.
                      How do I get around it?
                      It is possible that some change in IE has started to cause the function
                      you call to start throwing exceptions and prevent your onclick handlers
                      ever getting to the - return false; - statement. It is identifying that
                      change that will facilitate the correct solution to your problem.
                      Testcase:
                      -----------------------
                      >
                      <html>
                      >
                      <body>
                      <phello1 </p>
                      <a href = 'http://www.yahoo.com' onclick="alert( 'clicked');
                      return false;">my test link</a>
                      </body>
                      </html>
                      If you are going to post a test case it is always a good idea to test it
                      yourself to verify that it does demonstrate what you expect it to
                      demonstrate. In practice this test case shows the alert and does not
                      navigate the browser (using IE7 version: 7.0.5730.11. on Windows XP
                      SP2).

                      Richard.


                      Comment

                      • Duncan Booth

                        #12
                        Re: onclick=&quot;a lert('hello');r eturn false;&quot; does not work in IE7?

                        "Richard Cornford" <Richard@litote s.demon.co.ukwr ote:
                        >Testcase:
                        >-----------------------
                        >>
                        ><html>
                        >>
                        ><body>
                        ><phello1 </p>
                        ><a href = 'http://www.yahoo.com' onclick="alert( 'clicked');
                        >return false;">my test link</a>
                        ></body>
                        ></html>
                        >
                        If you are going to post a test case it is always a good idea to test it
                        yourself to verify that it does demonstrate what you expect it to
                        demonstrate. In practice this test case shows the alert and does not
                        navigate the browser (using IE7 version: 7.0.5730.11. on Windows XP
                        SP2).
                        The test case *as the OP posted it* does show what he claimed. It shows the
                        alert and then navigates to the link (in any browser, not just IE 7).

                        Maybe the bad line-break wasn't his original problem, but it seems a touch
                        unfair to chastise him for posting a bad test case when in fact what he
                        posted did what he said until you corrected the line wrapping.

                        Comment

                        • Richard Cornford

                          #13
                          Re: onclick=&quot;a lert('hello');r eturn false;&quot; does not work in IE7?

                          Duncan Booth wrote:
                          Richard Cornford wrote:
                          >>Testcase:
                          >>-----------------------
                          >><html>
                          >><body>
                          >><phello1 </p>
                          >><a href = 'http://www.yahoo.com' onclick="alert( 'clicked');
                          >>return false;">my test link</a>
                          >></body>
                          >></html>
                          >>
                          >If you are going to post a test case it is always a good
                          >idea to test it yourself to verify that it does demonstrate
                          >what you expect it to demonstrate. In practice this test case
                          >shows the alert and does not navigate the browser (using IE7
                          >version: 7.0.5730.11. on Windows XP SP2).
                          >
                          The test case *as the OP posted it* does show what he
                          claimed. It shows the alert and then navigates to the
                          link (in any browser, not just IE 7).
                          So it does not show any change between IE 6 and 7, and as the OP's
                          question took the form "What ahs changed?" (in part) its obviously
                          faulty formatting can be dismissed as ineptitude on the part of the
                          individual doing the posting.
                          Maybe the bad line-break wasn't his original problem, but it
                          seems a touch unfair to chastise him for posting a bad test
                          case when in fact what he posted did what he said until you
                          corrected the line wrapping.
                          But if he had tested what he had before he posted it he would not have
                          found that it did not exhibit the behaviour attributed to it, and
                          instead of having our time wasted with miss-attributed cause we could
                          have been looking at something that really has changed between IE 6 and
                          7 and maybe learnt something of ongoing practical use (though more
                          likely seen that an exploitable bug in IE 6 had finally been fixed).

                          Richard.


                          Comment

                          • Thomas 'PointedEars' Lahn

                            #14
                            Re: onclick=&quot;a lert('hello');r eturn false;&quot; does not work in IE7?

                            RobG wrote:
                            alvin.yk@gmail. com wrote:
                            [...]
                            >Testcase:
                            >-----------------------
                            >>
                            ><html>
                            >>
                            ><body>
                            ><phello1 </p>
                            ><a href = 'http://www.yahoo.com' onclick="alert( 'clicked');retu rn
                            >false;">my test link</a>
                            ></body>
                            ></html>
                            >
                            The HTML is invalid, an A element must be inside a block element.
                            IBTD.
                            I'm amost certain that has nothing to do with it, particularly where IE
                            is concerned, but you never know! ;-)
                            When there is no DOCTYPE declaration in the markup, or one that can be
                            deduced from additional facts in the posting (like VK stating Validator
                            results), it makes little sense to point out possible invalid snippets,
                            provided that there is an active (X)HTML standard that can be referred to
                            where it can still be Valid.

                            For example, if the above HTML code was declared HTML 4.01 Transitional (as
                            it would be considered by a recent UA implementing a Quirks Mode), would
                            still be not pretty, but perfectly Valid.


                            Regards,

                            PointedEars
                            --
                            The German psychs, the German authorities, the German secret service agents
                            are [...] fanatics, they are insane and known of persecuting innocent people
                            and Scientologists. -- "The only real Barbara Schwarz", dsw.scientology ,
                            <16d1deb5.04022 60945.4d4316af@ posting.google. com>

                            Comment

                            Working...