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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:47:48+00:00 2026-05-15T00:47:48+00:00

I have a custom web part placed on one of the application page in

  • 0

I have a custom web part placed on one of the application page in SharePoint. This page it seems already have a function which gets executed on windows beforeunload Javascript event.

My problem is that I too need to execute some client side code (to prompt user for any unsaved changes in my web part) on windows beforeunload event.

How can I achieve this? I mean let the default event be fired as well as call my function also?

Appreciate any help.

  • 1 1 Answer
  • 1 View
  • 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-15T00:47:48+00:00Added an answer on May 15, 2026 at 12:47 am

    This should be possible by checking for an existing handler assigned to the onbeforeunload event and, if one exists, saving a reference to it before replacing with your own handler.

    Your web part might emit the following script output to do this:

    <script type="text/javascript">
    
    // Check for existing handler
    var fnOldBeforeUnload = null;
    if (typeof(window.onbeforeunload) == "function") {
        fnOldBeforeUnload = window.onbeforeunload;
    }
    
    // Wire up new handler
    window.onbeforeunload = myNewBeforeUnload;
    
    // Handler
    function myNewBeforeUnload() {
        // Perform some test to determine if you need to prompt user
        if (unsavedChanges == true) {
            if (window.confirm("You have unsaved changes. Click 'OK' to stay on this page.") == true) {
                return false;
            }
        }
    
        // Call the original onbeforeunload handler
        if (fnOldBeforeUnload != null) {
            fnOldBeforeUnload();
        }
    }
    
    </script>
    

    This should allow you to inject your own logic into the page and make your own determination as to what code executes when the page unloads.

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

Sidebar

Related Questions

I have a custom navigation menu for my SharePoint intranet web application which is
I have created a SharePoint web part which has custom properties that the user
I would like to have a custom web part page in SharePoint 2007. I
I have a custom Sharepoint 2010 web part that runs the user through a
We have a custom PHP/MySQL web application that gets updated and copied (using SFTP)
I have a custom desktop application which invokes an ASMX web service. The Service
I have a problem with SharePoint custom web part. It was successfully deployed and
I have a custom web application that integrates with a SharePoint (MOSS 2007) solution.
I have a custom SharePoint web part that I have deployed as farm solution
Background: I have a built-in-house custom SharePoint 2010 web part, inheriting from System.Web.UI.WebControls.WebParts.WebPart ,

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.