Question

In Google Chrome, the following code snippet:

<html xmlns = "http://www.w3.org/1999/xhtml">
    <head>
        <title>Example</title>              
        <script type = "text/javascript">
        <!--
            function onBodyLoad()
            {               
                var x = 42;
                document.writeln("x = " + x);
                alert("on load");
            }
        -->
        </script>
    </head>

    <body onload = "onBodyLoad()"></body>
</html>

Is not writing

x = 42

to the document. The alert however is displayed. The text and the alert are both displayed in IE8 and FF 3.5. Any thoughts?

Was it helpful?

Solution

You have to do a document.close() after document.writeln():

            function onBodyLoad()
            {                               
                    var x = 42;
                    document.writeln("x = " + x);
                    alert("on load");
                    document.close();
            }

See: this question as well.

OTHER TIPS

Edit: Check and see if this post helps. I dont use chrome and you have to add document.close();

; missing in document.writeln("x = " + x) (?)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top