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

  • SEARCH
  • Home
  • 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've inherited a medium sized project in which the main (batch) program is fed
Once again, I have a problem for which I would like to shave off
Let's say I have a legacy application that, for various reasons, previous developers decided
for a client, I have been developing an app which has been tailored to
I have the following template template<typename T> void f(T t) { } And I
I'm working on a small library for for ASP.NET MVC 3 that should offer
I'm using Perl as my scripting language of choice under Windows and normally I
I'm wondering what makes it so hard for companies to be on time when
While i does manage to connect to my database through the Services netbeans tab,

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.