1.The write() method writes HTML expressions or JavaScript code to a document.
2.The write() method is mostly used for testing: If it is used after an HTML document is fully loaded, it will delete all existing HTML.
Note: When this method is not used for testing, it is often used to write some text to an output stream opened by the document.open() method. See "More Examples" below.
Tip: The document.writeln() method is similar to write(), only it adds a newline character after each statement.
Syntax: document.write(exp1, exp2, exp3, ...)
Different types of way how to define document.write() method in program.
CODING:2.The write() method is mostly used for testing: If it is used after an HTML document is fully loaded, it will delete all existing HTML.
Note: When this method is not used for testing, it is often used to write some text to an output stream opened by the document.open() method. See "More Examples" below.
Tip: The document.writeln() method is similar to write(), only it adds a newline character after each statement.
Syntax: document.write(exp1, exp2, exp3, ...)
Different types of way how to define document.write() method in program.
<html>
<body>
<button onclick="Function1()">Click ME</button>
<button onclick="Function2()">OPEN WINDOW</button>
<script>
function Function1() {
document.write("<h1>Hello World</h1>");
document.writeln("<h2>Have a nice day!</h2>");
document.write("GOOD BY..");
}
function Function2() {
var myWindow = window.open("HI", "MsgWindow", "width=500,height=500");
myWindow.document.write("<h1>Hi I am new Window</h1>");
myWindow.document.write("Hello World!");
myWindow.document.writeln("Have a nice day!");
myWindow.document.write("GOOD BY..");
}
document.write(Date());
</script>
</body>
</html>
<body>
<button onclick="Function1()">Click ME</button>
<button onclick="Function2()">OPEN WINDOW</button>
<script>
function Function1() {
document.write("<h1>Hello World</h1>");
document.writeln("<h2>Have a nice day!</h2>");
document.write("GOOD BY..");
}
function Function2() {
var myWindow = window.open("HI", "MsgWindow", "width=500,height=500");
myWindow.document.write("<h1>Hi I am new Window</h1>");
myWindow.document.write("Hello World!");
myWindow.document.writeln("Have a nice day!");
myWindow.document.write("GOOD BY..");
}
document.write(Date());
</script>
</body>
</html>
Comments
Post a Comment