Jump to content

document.write()

- - - - -

  • Please log in to reply
6 replies to this topic

#1
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
Hello, how are you?
I have one question. Could I write HTML code width a document.write()?

For example:
document.write("<br>");
I want to write "<br>" as a string in a Browser.

Thanks a lot. :c-smile:

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
document.write('hi[B]<br/>[/B]hi');

More special characters can be found here -->HTML ISO-8859-1 Reference

#3
VakhoQ

VakhoQ

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
Thanks :)

#4
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
It might be easier to modify an element. If you do a document.write it often messes up the rest of your code.

<div id="modifier">Hello world</div>
<script type="text/javascript">
document.getElementById('modifier').innerHTML = "Hello world<br />";
</script>
However the "br" is actually an element. You could create and append it.
<script type="text/javascript">
document.getElementById('modifier').innerHTML = document.createElement('br');
</script>

Edit: I skimmed to fast and saw you meant as a string.

Javascript has an "escape" function to help with this.

#5
dunnee

dunnee

    Newbie

  • Members
  • Pip
  • 1 posts
All HTML tags work within the "document.write("")" function in javascript.
Text and Tags must go in the "", variables etc can be outside the "" but within the ().
If that makes sense.

#6
gokuajmes

gokuajmes

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 518 posts
Document objects Write method will alter your HTML page. You should use the innerHTML property to set the contents of an element like textbox, span, div etc.
ex:
function onLoad(){
document.getElementById('divtowriteID').innerHTML = 'Hi i am CodeCaller';
}
<body onload="onLoad">


#7
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts

gokuajmes said:

Document objects Write method will alter your HTML page. You should use the innerHTML property to set the contents of an element like textbox, span, div etc.
ex:
function onLoad(){

document.getElementById('divtowriteID').innerHTML = 'Hi i am CodeCaller';

}

<body onload="onLoad">


does
<body onload="onLoad">
work on ie6?
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users