Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Avoid "Leave site?" pop-up

Posted on by 420

Hi friends, 

Users have recently started reporting an issue where they get a browser notification when trying to click a custom button in the ribbon which launches a dialog.  Specifically this only occurs following them modifying the record in some way, if they press the button following the initial form load they don't get this warning.  This is happening in IE11, Chrome, and Chromium based Edge. 

IE11 warning:

Are-you-sure-you-want-to-leave-this-page_2E00_.PNG

Chrome:

Leave-site.PNG

So steps to recreate:

1. Navigate to a case and open the form

2. Add a note to the case

3. Click the button to launch the dialog in the menu

 create-case-query.PNG

4. Receive browser notification

(Users then have to 5. refresh form 6. press button again to launch dialog)

I've stripped off all other javascript functions and business rules on the form but still have the issue.  This seems to have become an issue since moving away from the showModalDialog approach to launching dialogs/browser windows. 

Any suggestions appreciated. 

Thanks

Alex

My javascript is here:

function LaunchCaseQueryDialog() {

    var dialogId = "DCFD17F8-FA73-E411-9AB9-00155D014001";

    // Launch Dialog
    var serverUri = Mscrm.CrmUri.create('/cs/dialog/rundialog.aspx');
    var recordId = Xrm.Page.data.entity.getId();
    var width = 650; 
    var height = 720;
    var posLeft = window.outerWidth / 2 + window.screenX - ( width / 2);
    var posTop = window.outerHeight / 2 + window.screenY - ( height / 2);
    var win = window.open(serverUri + "?DialogId=" + dialogId + "&EntityName=incident&ObjectId=" + recordId, null, "height=" + height + ",width=" + width + ",left=" + posLeft + ",top=" + posTop + ",resizable=1,status=1,scrollbars=1 ");

    // Timer workaround to reload form on completion of dialog now that modal dialogs are deprecated in Chrome.
var timer = setInterval(function() {  
   if(win.closed) {  
       clearInterval(timer);  
       Xrm.Page.data.refresh();  
   }  
}, 1000);
}


(Dynamics version 1612 8.2.2.112 on premises)

*This post is locked for comments

  • Suggested answer
    AlexJay Profile Picture
    AlexJay 420 on at
    RE: Avoid "Leave site?" pop-up

    Just for reference in case it helps anyone. 

    This was resolved by explicitly naming the new query window and also using win.focus()

    Updated code below:

    function LaunchCaseQueryDialog() {

    var dialogId = "DCFD17F8-FA73-E411-9AB9-00155D014001";

    // Launch Dialog
    var serverUri = Mscrm.CrmUri.create('/cs/dialog/rundialog.aspx');
    var recordId = Xrm.Page.data.entity.getId();
    var width = 650;
    var height = 720;
    var posLeft = window.outerWidth / 2 + window.screenX - ( width / 2);
    var posTop = window.outerHeight / 2 + window.screenY - ( height / 2);
    var win = window.open(serverUri + "?DialogId=" + dialogId + "&EntityName=incident&ObjectId=" + recordId, "myquerywindow", "height=" + height + ",width=" + width + ",left=" + posLeft + ",top=" + posTop + ",resizable=1,status=1,scrollbars=1 ");
    win.focus();

    // Timer workaround to reload form now that modal dialogs are deprecated in Chrome.
    var timer = setInterval(function() {
    if(win.closed) {
    clearInterval(timer);
    Xrm.Page.data.refresh(); // window.location.reload(true)
    }
    }, 1000);
    }

  • AlexJay Profile Picture
    AlexJay 420 on at
    RE: Avoid "Leave site?" pop-up

    Hi Pravin,

    Thanks for the response and the suggestion.  I've tried to check for any dirty fields using your code before attempting to open the window, but none apparently are.  I've also tried adding a save step ahead of the open but this also doesn't seem to work.

    Thanks

    Alex

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Avoid "Leave site?" pop-up

    Hi Alex Yeoman,

    There might be any field is in dirty state on a form. In your coding you are trying to refresh page but somehow dirty field not allowing you to refresh.

    Please refer following code to find dirty field and make sure that field is saved in db.

    //get list of dirty fields

    var allAttributes = Xrm.Page.data.entity.attributes.get();

    if (allAttributes != null) {

       for (var i in allAttributes) {

           if (allAttributes[i].getIsDirty()) {

               listofDirtyAttri += allAttributes[i].getName() + "\n";

           }

       }

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans