Friday, December 19, 2008

Writing text to an iframe in Javascript

A simple example - writing text to an iframe - note that if you don't close() the document each time then firefox shows you it's still downloading the outer page content - on vista you'll see the circle of download.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head>

    <title>Untitled Page</title>

</head>

<body>

       

<script type="text/javascript">

    var i = 0;

    function doThing() {

        i++;

        var a = document.getElementById("stepsAchieved");

        a.contentWindow.document.write("Here again " + i + "<br/>");

        a.contentWindow.document.close();

    }

</script>       

<input type="button" value="hello" onclick="doThing();return false;" id="fred"/>

<hr />

        <iframe src="" id="stepsAchieved" name="garminStepsAchieved" frameborder="1" height="200px" width="340px" scrolling="auto">

        </iframe>

</body>

</html>

No comments:

Post a Comment