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.

4
  • You could call the script directly, without the html. <script src="remote.js"></script> Commented Nov 19, 2019 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. Commented Nov 19, 2019 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. Commented Nov 19, 2019 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. Commented Nov 19, 2019 at 16:19

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.