Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

onload event not triggering in html webresource

Posted on by 3,610

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

  • Verified answer
    Mohsin Ali Profile Picture
    Mohsin Ali 3,610 on at
    RE: onload event not triggering in html webresource

    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>

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: onload event not triggering in html webresource

    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 () {

               });

  • Mohsin Ali Profile Picture
    Mohsin Ali 3,610 on at
    RE: onload event not triggering in html webresource

    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
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: onload event not triggering in html webresource

    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>

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans