Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DOCUMENT.WRITE SYNTAX PROBLEM

Status
Not open for further replies.

alexfusion

Programmer
Feb 5, 2001
94
AR
Hello Everyone;
I use a script to write HTML in a new window,but I have a problem about the correct syntax.
For instance:
<script language=&quot;javascript&quot;>
function showwindow()
{
properties=&quot;toolbar=no,scroolbars=no,width=200;height=100,
top=100,left=100&quot;
newwindow=window.open(&quot;&quot;,&quot;name&quot;,properties)
content=&quot;&quot;
content+=&quot;<html>&quot;
content+=&quot;<head></head>&quot;
content+=&quot;<body bgcolor='#FFFFFF'>&quot;
content+=&quot;<div align='center'&quot;+&quot;>&quot;
content+=&quot;This is a child window&quot;
content+=&quot;</div>&quot;
content+=&quot;</body></html>&quot;
newwindow.document.open()
newwindow.document.write(content)
newwindow.document.close()
}
</script>
<body onload=&quot;showwindow()&quot;>
Etc.
I would like to know what is the right syntax to write HTML with Javascript.
Do I have to use double quotations for HTML tags an single for HTML atributes or viceversa?
I tried the first way and it works fine.Using the other syntax works OK too when I try it in my own computer.But when I upload the file to a server I get a Javascript syntax error.
I have seen different examples in books and the web using the two ways.
What is the correct syntax?
I'm sorry if this is too long.I dind't know how to explain it.

Can anyone give me some help?
Thanks in advance


alexfusion

mixale@hotmail.com


 
Since I can't tell whether or not this forum wrapped your text or whether you have an actual carriage return, let me just mention that you want to make sure that the line that sets the properties for the new window does not have an actual carriage return like it shows in this forum. And it probably doesn't.

OK, while we're on the subject, you have a semi colon between the width and height attributes in your properties setting. While this won't cause a JavaScript error, unless you change that to a comma, your sub window may not open the way you want it to. In IE 5, the window opened skinny and long. When I changed that to a comma, the new window opened to it's correct paramaters.

After I changed that semi colon to a comma and made sure my properties settings line was all one line in the function, I could not get IE or Netscape to generate an error. I have error notification on in IE and I checked the error log in Netscape and found nothing.

The function worked beautifully and I am actually impressed on how you wrote the function. I don't think you can write it any better than that. You didn't miss a beat. And yes, you should be able to use the same convention you are using with single quotes in the HTML.

If you're still having problems, maybe you can attach the page to an email or send me a web link to the page so I can take a look. sendpage@fuelaccess.com

ToddWW




 
Hello, alexfusion.

The major problem which has caught my eye is that you systematically leave out the end-of-statement character in your function written in javascript. I do not think it is a good practice. At time, it may not trigger any error in browser environment the main mission of which is to display the best it could the page, but errors inevitably surface if you do it systematically.

regards - tsuji
 
Hi TodWW and tsuji:
Sorry it tool so long to respond.
Thanks a lot for your excellent help!
The semicolon in the window properties is a typing error of mine when I posted the question.And you are correct,there is no carriage return in the script.

Once again thank you to you both for your professional advice and kindness.


alexfusion
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top