0

I have an html file on remote server ,

<!DOCTYPE html>
<html>
<body>
<div > Some content</div>

<script>
function myFunction(){
 alert("Hello");
}
</script> 

</body>
</html>

And from my main server html page I have to load this page and execute the java script function myFunction()

So I have loaded the page like

    <div id="main_id"></div>

    <script>
    function init(){
    var url = "remote.html";
    document.getElementById("main_id").innerHTML='<object type="text/html" style="width:100%;height:100%;" data='+url+' ></object>';
}
    $(document).ready(init);
    </script> 

But no idea how I can execute the JavaScript.

CodeDezk
  • 1,230
  • 1
  • 12
  • 40
  • You could call the script directly, without the html. `` – Afia Nov 19 '19 at 15:43
  • `$(document).ready(init());` is wrong and `$(document).ready(init);` is right if you are actually including jQuery in the page which I do not see in your code. – epascarello Nov 19 '19 at 15:46
  • Yes, actually I forgot add that part(typing error), the jquery part and the second page load works fine, but the problem is with executing javascript function on remote html, actually I have to load the remote html to div as well as execute javascript function. – CodeDezk Nov 19 '19 at 15:52
  • @CodeDezk The javascript function that you want to execute can be written on the onload event of the child page. When it is rendered within the page, the function will execute on onload event. – Arun Selin Nov 19 '19 at 16:19

0 Answers0