javascript function on a window object, when invoked, replaces that window's contents? (sometimes??) -


for reasons shall not enumerated here, i've found potentially useful attach functions window object. however, i've discovered rather weird behavior.

<html><head><script> function sideeffect() { console.log("side effect happened. wewt."); } window.foo = function() {     sideeffect();     return true; } window.bar = function() {     sideeffect(); } </script></head> <body> <a href="javascript:window.foo();">replaces entire window "true"</a> <br /> <a href="javascript:window.bar();">doesn't</a> </body></html> 

why invoking function return value decide replace window's contents? happens in firefox , opera, not in ie9, chrome, or safari (all tested on win7).

so question this: there sort of documentation specifies behavior? or (known) bug in ff/opera?


[edit] interestingly (according answers , comments thusfar) appears abuse of window object red herring here.

your code working perfectly--the browser doing telling do.

javascript lines valid in url bar of web browsers, , browser execute them immediately. (try it: write alert box in url bar, hit enter, , see happens.) writing javascript href of anchor tags, setting location of browser (in other words, url) line of javascript. because 1 of functions returns value, document on written value; normal browser behavior.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -