Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Safari - Javascript document.write needs tags?
Old 03-25-2006, 10:39 AM Safari - Javascript document.write needs tags?
Average Talker

Posts: 21
Trades: 0
New to the forum so please be gentle. Maybe this has been asked/answered but I've searched and don't have a clue.

In Safari – with a "document.write" command, the text is only written when enclosed in tags, any tags apparently; for example...

This works in Safari:

<script type="text/javascript">
function doit() {
document.write('<html>hello</html>');
}
</script>

(view at http://andexis.com/does.html)

This does not work in Safari but does work in I.E., Firefox and Opera:

<script type="text/javascript">
function doit() {
document.write('hello');
}
</script>

(view at http://andexis.com/doesnot.html)

So, please, embarrass me. Tell me what I've done wrong. Or it just a bug in Safari?
jimandy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-27-2006, 03:30 PM Re: Safari - Javascript document.write needs tags?
Super Talker

Posts: 144
Trades: 0
well, first off. using document.write after the page has finished loading, will reload your page with the text you are writing. using innerHTML is a way around this but hacky. I suggest using the DOM. Give your script an element for which the text will be placed and create a text element to put into that parenting element.

for instance...

Code:
<script type="text/javascript">
 
  function write_text(node, str) {
    node.appendChild( document.createTextNode(str) );
  }
 
</script>
 
<div id="my_div"></div>
 
<input type="button" name="add_text" value="add text" onclick="write_text(document.getElementById('my_div'), prompt('enter text', ''));">
__________________
create.vibe

Please login or register to view this content. Registration is FREE
createvibe.com is offline
Reply With Quote
View Public Profile Visit createvibe.com's homepage!
 
Reply     « Reply to Safari - Javascript document.write needs tags?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10021 seconds with 12 queries