Monday 24 June 2013

To Override document.write / alternative solution for document.write using javascript



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
hai
<div id="div"></div>

<script>
document.write = function(w) {
    document.getElementById("div").innerHTML += w;    //w has the write statement from document.write
}

document.write("Hello");
document.write("world");

</script>
</body>
</html>

No comments: