Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 general forum

Event trigger on custom HTML web resource whenever we navigate from the page

(0) ShareShare
ReportReport
Posted on by 219

Hi all,

I have a custom HTML web resource in the form. I'd like to know if there is a way to detect a navigation from the page and fire a javascript function. The problem is user can make several changes in the web resource and after that, he can navigate away from the current form. I want to save those changes in that case. Is this possible? Or maybe there's another way to achieve this?

Thanks,

Arsen.

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 Moderator on at
    RE: Event trigger on custom HTML web resource whenever we navigate from the page

    Hi,

    Please share the resolution details here and mark it as answer so that it can help others :)

  • Arsen Aghajanyan Profile Picture
    Arsen Aghajanyan 219 on at
    RE: Event trigger on custom HTML web resource whenever we navigate from the page

    Thanks guys. I was able to resolve this by using onbeforeunload handler and some simple code blocking techniques :)

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 Moderator on at
    RE: Event trigger on custom HTML web resource whenever we navigate from the page

    Ohh Okay, see if you can use session storage to store your values.

    developer.mozilla.org/.../sessionStorage

  • Arsen Aghajanyan Profile Picture
    Arsen Aghajanyan 219 on at
    RE: Event trigger on custom HTML web resource whenever we navigate from the page

    Hi Ravi,

    Thanks for your effort :) I know how to access parent form methods and fields. The problem is my web resource is within the same window as the parent form. So whenever we unload the main form, the web resource gets unloaded as well. So i need to fire some code whenever the t unload event fires.

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 Moderator on at
    RE: Event trigger on custom HTML web resource whenever we navigate from the page

    Hi Arsen,

    My suggestion was to get the info of the parent record which also include executing the methods. So if you have any JavaScript method on your parent, you can execute that as well using window.opener or window.parent. The other option was to again get the fields from the parent record so you have some kind of context  to access it later or use web api to save it externally.

    Refer this-community.dynamics.com/.../calling-custom-javascript-function-from-web-resource-on-parent-page

    Sad if this doesn't fit your requirement :)

  • Arsen Aghajanyan Profile Picture
    Arsen Aghajanyan 219 on at
    RE: Event trigger on custom HTML web resource whenever we navigate from the page

    Hi Ravi, thanks for your answer. The question is not about accessing the parent window fields from an html web resource actually. It's about firing event on parent window unload :)

    Thank you Goutam! I should definitely try those options.

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 Moderator on at
    RE: Event trigger on custom HTML web resource whenever we navigate from the page

    Hi Arsen,

    Typically when you open the HTML web resource from an entity form you can access the parent record fields from where the HTML is opened using "window.opener.Xrm.Page.data.entity.attributes.get(Schema_Street1)". The only thing is that it may not work if you navigate away from that entity record.

    The other option is to pass the record id from the entity record to the HTML and then use WEB API to update the record based on the details-

    dynamicscrmcoe.com/passing-data-crm-form-custom-html-web-resource

    www.inogic.com/.../how-to-pass-object-or-collection-of-objects-to-a-web-resource-in-crm-2011

    Hope this helps.

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 Moderator on at
    RE: Event trigger on custom HTML web resource whenever we navigate from the page

    Hi Arsen,

    There is no such OOB or supported method  for that however you could use JQUERY library or accessing  window properties . Try with this-

    https://api.jquery.com/unload/

    www.w3schools.com/.../event_onunload.asp

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

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