Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Dynamics CRM 9.1 - Close the window which was opened using Xrm.Navigation.openWebResource

(0) ShareShare
ReportReport
Posted on by 505


I'm using Xrm.Navigation.openWebResource method to open HTML page.

I have a button on this page.

How can I close the window on click of this button?

  • Suggested answer
    Priyank Bhavsar Profile Picture
    Priyank Bhavsar 505 on at
    RE: Dynamics CRM 9.1 - Close the window which was opened using Xrm.Navigation.openWebResource

    Unfortunately, none of the answers suggested worked for me. 

    Finally after lots of efforts, I got it working using the following code:

    Xrm.Navigation.openForm(windowOptions).then(
            function (success) {
                  window.close();
     });

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 Moderator on at
    RE: Dynamics CRM 9.1 - Close the window which was opened using Xrm.Navigation.openWebResource

    Hi Priyank ,

    If I  understood correctly you want to refresh the parent page where you actually put the button to open the web resource. In this case first you need to make sure you added following reference in the web resource html <head> section to access XRM object -

       <script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>

    And then write below code to refresh and the close the window -

                           window.parent.opener.Xrm.Page.data.refresh();

                           window.top.close();    

  • Suggested answer
    Charles Abi Khirs Profile Picture
    Charles Abi Khirs 3,569 on at
    RE: Dynamics CRM 9.1 - Close the window which was opened using Xrm.Navigation.openWebResource

    Hello,

    You can use "window.top.close();" as in my blog post: charlesabikhirs.blogspot.com/.../d365-html-web-resource-web-interface-vs.html

  • Priyank Bhavsar Profile Picture
    Priyank Bhavsar 505 on at
    RE: Dynamics CRM 9.1 - Close the window which was opened using Xrm.Navigation.openWebResource

    Yes, when the button is clicked on the web resource, I want to close the web resource and refresh the form.

    My code looks like this:

    $("#btnAddProducts").click(function () {
    
                    var isCloseProductwizard = CreateOrderProducts();
                    if (isCloseProductwizard) {
                        var orderID = getQueryStringValue("OrderID");
                        var windowOptions = {
                            openInNewWindow: false,
                            entityName: "salesorder",
                            entityId: orderID
                        };
                        Xrm.Navigation.openForm(windowOptions);
                        window.top.close();
                    }
    
     });

  • LeoAlt Profile Picture
    LeoAlt 16,331 Moderator on at
    RE: Dynamics CRM 9.1 - Close the window which was opened using Xrm.Navigation.openWebResource

    Hi partner,

    Did you mean you want to refresh the form when closing the web resource?

    Could you show complete code and so that we could test it for you in environments.

    Best Regards,

    Leo

  • Priyank Bhavsar Profile Picture
    Priyank Bhavsar 505 on at
    RE: Dynamics CRM 9.1 - Close the window which was opened using Xrm.Navigation.openWebResource

     var windowOptions = {
                            openInNewWindow: false,
                            entityName: "salesorder",
                            entityId: orderID
                        };
                      
     Xrm.Navigation.openForm(windowOptions);

    I'm trying to reload the entity record using the above code. 

    After the above code executes I'm trying to close the window. 

    If I comment out the above code then both parent.window.close() and window.top.close() work but when I uncomment the above code, the window is not getting closed.

  • LeoAlt Profile Picture
    LeoAlt 16,331 Moderator on at
    RE: Dynamics CRM 9.1 - Close the window which was opened using Xrm.Navigation.openWebResource

    Hi partner,

    Please use "window.top.close()" to close the window opened by "Xrm.Navigation.openWebResource", it worked well both in UCI and classic.

    pastedimage1582514098125v1.png

    After I clicked on "close", this window closed as expected.

    Here's the sample code of the close button in web resource.

    
     
     
    Close Window 
     
    
    
    
     
    
    

    Hope it helps.

    Best Regards,

    Leo

  • Suggested answer
    rthompson Profile Picture
    rthompson 1,530 on at
    RE: Dynamics CRM 9.1 - Close the window which was opened using Xrm.Navigation.openWebResource

    This should do the job.

    //Close the existing open form

    parent.window.close();

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans