Please! help me out with this (its urgent)

S

syedfazalullah

Hi,

Is there any one who could help me to execute the following code
correctly.

<html>
<head>
<title>Some Title</title>
<script>
win=window.open('',null,'height=300,width=700');
var doc=win.document.open('text/html','replace');
doc.writeln('<html>');
doc.writeln('<head>');
doc.writeln('<script>');
doc.writeln('alert(\'This is a line\');');
doc.writeln('</script>');
doc.writeln('<body>');
doc.writeln('Hai! How are you doing?');
doc.writeln('</body>');
doc.writeln('</html>');
</script></head></html>
 
R

RobG

Hi,

Is there any one who could help me to execute the following code
correctly.

<html>
<head>
<title>Some Title</title>
<script>

The type attribute is required:

win=window.open('',null,'height=300,width=700');
var doc=win.document.open('text/html','replace');

document.open() does not take any parameters, but isn't needed anyway as
it is called automatically when document.write() is called.

doc.writeln('<html>');
doc.writeln('<head>');
doc.writeln('<script>');

The type attribute is required - you should write valid HTML always.

doc.writeln('alert(\'This is a line\');');
doc.writeln('</script>');

When included as a string in a write statement, the script endtag must
be treated with care - escape the slash:

doc.writeln(' said:
doc.writeln('<body>');
doc.writeln('Hai! How are you doing?');
doc.writeln('</body>');
doc.writeln('</html>');

All those document.writes() are very expensive. Create the window and
do a single write - either build up the HTML as a single text string and
write that or concatenate the text.

And don't forget to close the document at the end:


win = window.open('',null,'height=300,width=700');
var newHTML = '<html><head><script type="text/javascript">'
+ 'alert("This is a line");'
+ '<\/script></head>'
+ '<body>Hai! How are you doing?</body>'
+ '</html>';
win.document.write(newHTML);
win.document.close();


or:

win = window.open('',null,'height=300,width=700');
win.document.write(
'<html><head><script type="text/javascript">',
'alert("This is a line");<\/script></head>',
'<body>Hai! How are you doing?</body></html>'
);
win.document.close();
 
F

Fazal

Hi RobG,

I appreciate your immediate help.
Code given by you is working fine, and thanks, for tips to improve the
code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top