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

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Unable to call JavaScript function from HTML webresource added as an iFrame

(0) ShareShare
ReportReport
Posted on by 50

Hi Everyone,
I am using D365 9.1 online.  I have a section on a form. On click of this section, it needs to display a custom HTML webpage. Before I start creating my actual webpage, I created a prototype HTML webpage and added it as a webresource., I added an iFrame inside that section referencing this HTML page I created. I need to call some external JavaScript functions in this HTML page. I am not able to. Here is a snippet of my code:
HTML:



<!DOCTYPE HTML>
<html>
<head>
    <script src = "/WebResources/nikhilSampleJSPage" type="text/javascript"></script>
  
<title> <h1>Sample title</h1>  </title>
</head>
<body>
  testFunction();
<p> Sample paragraph.  </p>
</body>
</html>



JavaScript webresource:
function testFunction()
{
alert("Message box displayed successfully.");
}

I have my suspicions on why it is not working to the following:

  • Getting this message when I open developer tools - "Blocked script execution in is sandboxed and the 'allow-scripts' permission is not set dynamics 365".... Is this because I added the HTML page as an iFrame? If it is, how else can I accomplish displaying the custom HTML webpage on click of that section?
  • The URL of the Javascript webresource does not have the ".js" in the extension. It looks something like " orgUrl/WebResources/nikhilSampleJSPage" When I mentioned the script src in the html page, I tried with both ".js" removed and with it. Both does not seem to work. Is this the issue? Am I messing something up in mentioning the script source?
  • The heading and the paragraph is getting displayed.But the alert box is not.

Any help on this would be greatly appreciated. Thanks in advance.

I have the same question (0)
  • Verified answer
    Temmy Wahyu Raharjo Profile Picture
    2,914 on at
    RE: Unable to call JavaScript function from HTML webresource added as an iFrame

    1) For error "Blocked script execution..", you can read in Microsoft Documentation, they added "sandbox" attribute that you need to configure like this.

    2) You can check the full path of the WebResources in the bottom of the page to see either you put .js or not.033426.Capture.JPG

    3) I think the problem of why your javascript not loaded because you are wrong in the src. Based on this post, You supposed to only write <script src="nikhilSampleJSPage" type="text/javascript" /> or to be saved, just do "../WebResources/nikhilSampleJSPage" which means go up 1 level, go to WebResources Folder, and get nikhilSampleJSPage.

  • Verified answer
    Bipin D365 Profile Picture
    28,983 Moderator on at
    RE: Unable to call JavaScript function from HTML webresource added as an iFrame

    HI,

    Use below code which I have tested in my crm instance and it works as expected.

    
    
        
      
     <h1>Sample title</h1>  
    
    
    

    Sample paragraph.

    1. Change JS Web resource name with your JS Web resource Name. Make sure you provide prefix name in my case I have mentioned new_

    2. function call should be onload in body tag

    Please mark my answer verified if i were helpful

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at
    RE: Unable to call JavaScript function from HTML webresource added as an iFrame

    Hi Daniels,

    Try to refer to name of js web resource directly in your html web resource.

    My js web resource:

    5050.JPG

    Code of page:

    7851.JPG

    run function of the new_myFuntion web resource:

    pastedimage1602482893579v1.png

    Instead of with iframe, I insert the web as web resource directly to section of form.

    pastedimage1602483138239v2.png

    It works for me.

    From code of your HTML, it seems that the testFunction wasn't nested in script tag.

    Please put it within script tag or run it at onload event of page.

    Regards,

    Clofly

  • DDaniels Profile Picture
    50 on at
    RE: Unable to call JavaScript function from HTML webresource added as an iFrame

    Thank you all very much for your suggestions!! It worked. There were a few changes I had to make:

    1) <script src = "../WebResources/new_ContactForm" type="text/javascript"></script>    ---- I was missing the .. in the beginning of the folder path.

    2) I removed the restriction on cross side scripting for the iFrame in the configuration box.

    cross-frame-scripting.PNG

    3) As Bipin suggested - I added this line - <body onload="testFunction()">------ the ; should be removed and once it is removed it works.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 258

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 186

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 130 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans