Javascript and document.write

Posted By: mpdeveloper_B

Javascript and document.write - 09/04/09 15:59

I want to use a document.write command in javascript to write a line at the very beginning of the html file in which it is writing. I know how to use document.write(""); but I don't know how to tell the javascript to go to the very beginning of the html file. Can someone help me with this?
Posted By: Michael_Schwarz

Re: Javascript and document.write - 09/04/09 16:04

body.innerHTML = "hi there" + body.innerHTML;

should do the trick
Posted By: mpdeveloper_B

Re: Javascript and document.write - 09/04/09 16:21

I mean at the absolute beginning of the file, not the body. Before all the headers and everything. Line numero uno.
Posted By: mpdeveloper_B

Re: Javascript and document.write - 09/04/09 16:37

I have to put this line at the beginning of the html file by using javascript, can it be done?

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN">


Posted By: Michael_Schwarz

Re: Javascript and document.write - 09/04/09 16:53

html.innerHTML = "hi there" + html.innerHTML;

"should" work, but I'm not really sure.
Posted By: mpdeveloper_B

Re: Javascript and document.write - 09/04/09 17:02

no dice. I'm curious about this...is there a way to change the doctype in javascript...
Posted By: Joey

Re: Javascript and document.write - 09/04/09 17:06

no. but you can start a new document and write in everything plus the new doctype.
Posted By: mpdeveloper_B

Re: Javascript and document.write - 09/04/09 17:11

well, I guess that solves that tongue

I'll have to change the doctype manually then. I was asking because the website software that we use for yahoo doesn't set doctypes, which can cause some problems, and if you change the files out of the program and open them back up it deletes any changes to the beginning of the file so all doctypes are removed...

Oh well, guess that means anytime we update I'll have to change the doctype. Hopefully we won't have to update alot.
Posted By: Blade280891

Re: Javascript and document.write - 09/04/09 23:07

erm surely

<script>
document.write("");
</script>
<!doctype....

If that doesn't work and you need a solution i will be more than happy to create one for you
Posted By: Joey

Re: Javascript and document.write - 09/05/09 14:58

and how is that supposed to work?
Posted By: Blade280891

Re: Javascript and document.write - 09/05/09 17:00

Try it and find out
Posted By: Joey

Re: Javascript and document.write - 09/05/09 18:52

ok. it doesn't work and i need a solution.
Posted By: Blade280891

Re: Javascript and document.write - 09/05/09 19:08

Just wondering, why do you need to put it there using JS ?

Is is using an IF statement or ?
© 2024 lite-C Forums