Note that there are some explanatory texts on larger screens.

plurals
  1. USKP Taylor
    primarykey
    data
    text
    plurals
    1. CO@Pointy I just tried it on Chrome 11 (lazily downloaded the latest), and I see what you mean. It's not a total departure; JavaScript in the URL does work (for example, try `javascript: alert('hello');` or `javascript: document.write("hello");`, which does replace the contents of the browser window), but the syntax in the question above does *not* have the same effect, as you say. It doesn't appear that the JavaScript-in-the-address-bar that is the problem, but what Chrome does with the values. Very interesting...
      singulars
    2. CO@Bob For your second point, the function is being executed prior to the navigation event (even though the URL is changing to the function call itself), and the value of the function is what is being rendered on the page; thus, seeing "true" on the page is the result of the function call after the function has been invoked. You can see this in action, too, if you change the `foo()` function to return a string value such as "Hello"...the new page will say "Hello" instead of "true".
      singulars
    3. CO@Bob For your first point, see Andy E's comment above. Any value of `null`, `false`, or `undefined` in the href of an anchor causes the navigation to be cancelled--so the method that does not return a value is, on accident, cancelling the navigation--thus no blank page. You actually could "fix" (note the ironic quotes) the original code by re-writing it like this: `href="javascript:window.foo(); return false;"`
      singulars
 

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