By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,998 Members | 2,815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,998 IT Pros & Developers. It's quick & easy.

writeln and new line (\n) not working

P: n/a

Hello NG,
I have been making all my web pages in HTML and I just started using
JavaScript yesterday and ran into a brick wall!
I can get the escape character " \n " or document.writeln to give me a new
line.
Or for that matter any of the form feed " \f " or carriage return " \r
" to work either.
I can get the escape character " \" "
I'm using XP home with SP2 with IE6 all my security setting set to Prompt
so if that was an issue then at least I should get a prompt for allowing the
script to work.
I put my JavaScript in a .js file and have referenced it from the HTML page.
I've tried this on different machines that also use XP with IE6, is this a
problem with IE?
I've tried
<script type= "text/javascript" src="assets/beagle.js">
and
<script language="JavaScript1.2" src="assets/beagle.js">
Any ideas as to where I'm going wrong?
================================================== =========
here is the HTML part
<html>
<head>
<title> Welcome to my Beagle Page</title>
<!-- place all scripts below, in this area -->
<script language="JavaScript1.2" src="assets/beagle.js">

<!--

-->
</script>

<!-- place all scripts above, in this area -->

</head>
<body>
<CENTER><H1><FONT COLOR="#0000FF">Beagle Page</FONT></H1></CENTER>
</body>
</html>

================================================== ===========
and here is the beagle.js file

document.writeln("\"Welcome to my site! \"");
document.writeln("\n")
document.writeln
document.writeln("This page created by James Last update:\n" +
document.lastModified);

document.bgColor="black"
document.fgColor="#336699"
window.alert("Welcome to my site!")

================================================== =============
Thaks for any suggestions
James
"Go outside - the graphics are amazing!"
Jan 20 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
James wrote on 20 jan 2006 in comp.lang.javascript:
<html>
<head>
<title> Welcome to my Beagle Page</title>
<!-- place all scripts below, in this area -->
<script language="JavaScript1.2" src="assets/beagle.js">
So not sepecify the 1.2 and the wrong string, use:

<script type="text/JavaScript" src="assets/beagle.js">
<!--
do not use!
-->
do not use.
</script>

<!-- place all scripts above, in this area -->
Exept scripts with displayable html text, they should be in the <body>

</head>
<body>
<CENTER><H1><FONT COLOR="#0000FF">Beagle Page</FONT></H1></CENTER>
better use css:

<div style='text-align:center;color:#00f;'>
Beagle Page
</div>



</body>
</html>

================================================== ===========
and here is the beagle.js file

document.writeln("\"Welcome to my site! \"");
document.writeln("\n")
Probably you want tos show new lines in the browser, so use:
document.write('"Welcome to my site!"');
document.write("<br>")
document.writeln in contrast to document.write gives only an extra new
line in the internal source, that you won't see anyway without special
measures. so better use the latter.
document.writeln
not useful, leave out, or write a <br>.
document.writeln("This page created by James Last update:\n" +
same, \n will only affect the internal source code.
document.lastModified);

document.bgColor="black"
It is the body that uses colours, not documents:

document.body.bgColor="black"
document.fgColor="#336699"
but better use css styles:

document.body.style.backgroundColor = 'black';
document.body.style.color = '#369';

single quotes and end colon are optional, but advised.
window.alert("Welcome to my site!")



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 20 '06 #2

P: n/a
"James" <tvwatchr2@NO_SPAMearthlink.net> wrote in message
news:sh*************@newsread2.news.pas.earthlink. net...

Hello NG,
I have been making all my web pages in HTML and I just started using
JavaScript yesterday and ran into a brick wall!
I can get the escape character " \n " or document.writeln to give me a new line.
Or for that matter any of the form feed " \f " or carriage return " \r
" to work either.
I can get the escape character " \" "
I'm using XP home with SP2 with IE6 all my security setting set to Prompt
so if that was an issue then at least I should get a prompt for allowing the script to work.
I put my JavaScript in a .js file and have referenced it from the HTML page. I've tried this on different machines that also use XP with IE6, is this a
problem with IE?
I've tried
<script type= "text/javascript" src="assets/beagle.js">
and
<script language="JavaScript1.2" src="assets/beagle.js">
Any ideas as to where I'm going wrong?
================================================== =========
here is the HTML part
<html>
<head>
<title> Welcome to my Beagle Page</title>
<!-- place all scripts below, in this area -->
<script language="JavaScript1.2" src="assets/beagle.js">

<!--

-->
</script>

<!-- place all scripts above, in this area -->

</head>
<body>
<CENTER><H1><FONT COLOR="#0000FF">Beagle Page</FONT></H1></CENTER>
</body>
</html>

================================================== ===========
and here is the beagle.js file

document.writeln("\"Welcome to my site! \"");
document.writeln("\n")
document.writeln
document.writeln("This page created by James Last update:\n" +
document.lastModified);

document.bgColor="black"
document.fgColor="#336699"
window.alert("Welcome to my site!")

================================================== =============
Thaks for any suggestions
James
"Go outside - the graphics are amazing!"


You are using JavaScript to render HTML; therefore,
use "<br>" not "\n".

Here it is without the "include". Watch for word-wrap.

<html>
<head>
<title>Welcome to my Beagle Page</title>
<script type="text/javascript">
document.writeln("\"Welcome to my site! \"");
document.writeln("<br>This page created by James Last update:<br>" +
document.lastModified);
document.bgColor="black"
document.fgColor="#336699"
window.alert("Welcome to my site!")
</script>
</head>
<body>
<CENTER><H1><FONT COLOR="#0000FF">
Beagle Page</FONT></H1></CENTER>
</body>
</html>
It's not too readable with that color scheme!
Jan 20 '06 #3

P: n/a
Thanks for the help.
Things are working for me now and I learned something in the process
James

--

"Go outside - the graphics are amazing!"

Jan 20 '06 #4

P: n/a
On 2006-01-20, James <tvwatchr2@NO_SPAMearthlink.net> wrote:

Hello NG,
I have been making all my web pages in HTML and I just started using
JavaScript yesterday and ran into a brick wall!
I can get the escape character " \n " or document.writeln to give me a new
line.
Or for that matter any of the form feed " \f " or carriage return " \r
" to work either.


those symbols are only significant inside <pre> sections of your document
outside of them use <br> for as line break eg. document.write("<br>");

Bye.
Jasen
Jan 21 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.