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 459833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:48:44+00:00 2026-05-12T22:48:44+00:00

I want to bind a function to the beforeunload event of a child window

  • 0

I want to bind a function to the beforeunload event of a child window in Javascript.
I have the following code:

newWind = window.open(settings.url, "Dialog", "width=" + settings.width + ",height=" + settings.height + ",resizable=" + settings.resizable + ",scrollbars=" + true);

newWind.onunload = function() { alert('test'); }

Works fine in Firefox, but fails in IE7. Can anyone see what I am doing wrong?

  • 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-12T22:48:45+00:00Added an answer on May 12, 2026 at 10:48 pm
    newWind.onunload = function() { alert('test'); }
    

    IE won’t let you assign a function from one window context to another window’s on[before]unload, for some reason. You can assign a foreign function to other event handlers, including newWind.document.body.onunload, but it’s not a good idea.

    Firstly because IE’s garbage collection is window-based so if you close or navigate the opener window, the pop-up will try to execute a dead function, or function with dead variables in scope, resulting in weird JavaScript errors.

    And secondly because you don’t know from the opener when the popup document is loaded enough to be able to set the handler. At the point just after the open call, the popup document may not have started loading at all, in which case you can’t safely set any event handlers on it. So you would need a short delay before setting the onunload handler, and the user might close the window in that time. And the opener doesn’t know how long to delay; instead, the child dialog would have to call the parent back to tell it it’s ready. Better to have the child pop-up take charge of receiving its own events and calling the opener to let it know about them.

    Cross-window scripting has endless pitfalls. Try to avoid it wherever possible. For dialogs always use in-page elements, which are much more reliable and less annoying than window popups.

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

Sidebar

Related Questions

I have this jQuery code; $(function () { $(window).unbind(beforeunload); $(window).bind(beforeunload, function () { return
I have a function SomeFunction(event) - I want to bind a 'tap' event to
I want to bind a click event with the element: $('a').click(function(){ btn_submit_pressed=false; }); Now,
The documentation says to use: $(input[type='checkbox']).bind( change, function(event, ui) { But I want to
i want https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind#Currying in PHP: $x = function ($a, $b) { echo $a .
i want to build an object using this code $(input).bind(keydown,function(e){ var code = (e.keyCode
I want to dynamically (in a loop) bind a function to the .click() event
I have some elements with a function bound to the click event. I want
i have an input element, and i want bind both change and keypress event
Using jQuery I want to bind an existing function to a button. I've been

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.