Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4260054
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:52:07+00:00 2026-05-21T05:52:07+00:00

For reasons which shall not be enumerated here, I’ve found it potentially useful to

  • 0

For reasons which shall not be enumerated here, I’ve found it potentially useful to attach functions to the 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 with "true"</a>
<br />
<a href="javascript:window.bar();">Doesn't</a>
</body></html>

Why exactly does invoking a function with a return value decide to replace the window’s contents? This happens in Firefox and Opera, but not in IE9, Chrome, or Safari (all tested on Win7).

So the question is this: Is there some sort of documentation that specifies this behavior?
Or is this a (known) bug in FF/Opera?


[edit] Interestingly (according to answers and comments thusfar) it appears that the abuse of the window object is a red herring here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:52:08+00:00Added an answer on May 21, 2026 at 5:52 am

    Your code is working perfectly–the browser is doing exactly what you are telling it to do.

    JavaScript lines are valid in the URL bar of web browsers, and the browser will execute them immediately. (Try it: write an alert box in the URL bar, hit enter, and see what happens.) By writing your JavaScript into the href of your anchor tags, you are setting the location of the browser (in other words, the URL) to that line of JavaScript. Because one of your functions returns a value, the document is over written by that value; this is normal browser behavior.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a GTK Window which, for various reasons, I wish to make
Our J2ee server (which will remain nameless for embarrassment reasons) slows down drastically from
My git repo contains sensitive passwords which, for reasons out of my control, can't
We have an application which has about 15000 pages. For better SEO reasons we
Is there a reason why java does not have a class which allows both
For a number of reasons (all of which can, basically, be broken down to
I have to implement an algorithm on data which is (for good reasons) stored
I have two SWF files which I shall call container and slave . The
For some reason my Tinyxml file which is created via visual studio 2005 (c++)
I have some tables for which I have no reason to ever update from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.