Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To tie both of the very-correct answers together, what's happened is you've inlined a function where you've written <code>onclick="return runFunction();"</code></p> <p>If you look at that, what it's really doing is going like this:</p> <pre><code>var link = document.getElementById("myLink"); link.onclick = function () { runFunction(); }; </code></pre> <p>See the problem?</p> <p>My <code>runFunction</code> is being called without any event object passed in, at all. ...which means that <code>var thisLink = (evt) ?</code> is going to return false, which means that it's going to try to run in oldIE-mode.</p> <p>By writing <code>onclick="runFunction"</code>, that's the same as saying:</p> <pre><code>link.onclick = runFunction; </code></pre> <p>Which means that when the onclick event happens, runFunction will be called, and in W3C-compliant browsers, it will be sent an event object.</p> <p>Which is why that solution works.</p> <p>The best way to avoid a lot of this confusion is to deal with JavaScript from inside of JavaScript, and to deal with HTML inside of HTML, so that you don't have to worry about how strings translate into code.</p> <p>Now, to get all of this to work, AND prevent redirection, you want to do this:</p> <p>for W3C browsers (the ones that pass the event parameter):</p> <pre><code>function runFunction (evt) { // stops the default-action from happening // means you need to find another way to fire it, if you want to later evt.preventDefault(); // stops higher-up elements from hearing about the event // like if you stop a submit button from "clicking", that doesn't stop the form // from submitting evt.stopPropagation(); //the oldIE versions of both of these are event.cancelBubble = true; event.returnValue = false; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload