web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
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?

I have the same question (0)
  • Suggested answer
    rthompson Profile Picture
    1,532 on at

    This should do the job.

    //Close the existing open form

    parent.window.close();

  • LeoAlt Profile Picture
    16,331 Moderator on at

    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

  • Priyank Bhavsar Profile Picture
    505 on at

     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
    16,331 Moderator on at

    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
    505 on at

    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();
                    }
    
     });

  • Suggested answer
    Charles Abi Khirs Profile Picture
    3,569 on at

    Hello,

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

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    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
    Priyank Bhavsar Profile Picture
    505 on at

    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();
     });

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 180 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 123

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans