Controlling the scope of a document.write call coming from a third party

Posted by pingrey on Stack Overflow See other posts from Stack Overflow or by pingrey
Published on 2010-06-02T16:21:19Z Indexed on 2010/06/02 16:24 UTC
Read the original article Hit count: 325

Dear all,

I'm writing a webpage that relies on an external javascript file (that I have no control of), which returns data by using document.write's. Is there any way to dynamically call the function without it overwriting the whole document? The most concise code I can think of is below:

<html>    
<head>
<script type="text/javascript">
    function horriblefunction () {
        document.write("new text");
    }
</script>
</head>

<body>
Starting Text...
<div id="pleasewriteinme"></div>
Other text...
<button onclick="horriblefunction();">Click</button>
</body>
</html>

The idea beginning that without altering "horriblefunction()" (as it's external) the new text could be placed in the div instead of overwriting the page. Is this possible or does the function have to be called inside the div as the page is created?

Thanks for you help

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html