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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

onload event not triggering in html webresource

(0) ShareShare
ReportReport
Posted on by 3,634

I am trying to fire following onload event in an HTML webresource in dynamics CRM. But it seems not working without any exception thrown. I tried with both options but still no luck, any idea?

https://community.dynamics.com/crm/f/117/t/234028

https://social.microsoft.com/Forums/en-US/4969a015-59f6-4d1d-a582-d36ecf2cec24/crm-2013-html-web-resource-removed-body-onload-event?forum=crmdevelopment

<!DOCTYPE html>

<html>
<head>
    <title>User Security Roles</title>
	<script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
    <script src="../WebResources/new_xrmservicetoolkit" type="text/javascript"></script>
    <script type="text/javascript">
        function getLoggedInUserRoles() {
			alert("Onload event triggered.");
        }
    </script>
	 window.onload = call;
</head>
<body onLoad="getLoggedInUserRoles()"> 
</body>
</html>


*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at

    Hi Mohsin,

    Can you please add .js extension after your js reference file as follows:

    <script src="../WebResources/new_xrmservicetoolkit.js" type="text/javascript"></script>

  • Mohsin Ali Profile Picture
    3,634 on at

    This might not be the case for the failure because same script works fine once I added it on click event of a button. So the problem is when I add the script at onLoad event of body.

    Imagine I created the web resource of HTML type, copy and paste the this source code and close the window. But I reopen the webresource the onLoad event was removed.

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

    Hi Mohsin,

    Your code is correct , but not sure why its not working. Alternate way can you please try to call function inside document.ready function.

               $(document).ready(function () {

               });

  • Verified answer
    Mohsin Ali Profile Picture
    3,634 on at

    Thank you both, I did two mistakes in script.

    1. Window.onload was out of the script section

    2. window.onload was referring to an invalid method.

    I changed the script section and everything work fine.

    <script type="text/javascript">

           function getLoggedInUserRoles() {

    alert("Onload event triggered.");

           }

    window.onload = getLoggedInUserRoles;

       </script>

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans