/    Sign up×
Community /Pin to ProfileBookmark

HELP!!! about "document.write()"

EXAMPLE:
<html>
<script language = javascript>
document.write(“<table width=’750′ border=’5′> <tr><td height=’74’><script src=explain.js></script></tr></td></table>”);
</script>
</html>

There is only one statement in “explain.js” :
document.write(‘WHO CAN HELP ME’);

QUESTION:
the content in explain.js “WHO CAN HELP ME” doesn’t printed into the table. It just displayed after the table.

But if the page likes

<html>
<script language = javascript>
document.write(“<table width=’750′ border=’5′> <tr><td height=’74’><script language=javascript>document.write(‘WHO CAN HELP ME’);</script></tr></td></table>”);
</script>
</html>

it can run correctly.

I want to know wether the document.write() can load a .js file???

Thanx a lot !

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@neil9999Aug 12.2004 — Try this:

[CODE]<html>
[color=orange]<head>[/color]
[color=purple]<title>[/color]A table[color=purple]</title>[/color]
[color=orange]</head>[/color]
[color=pink]<body>[/color]
[color=green]<table width='750' border='5'>
<tr>
<td height='74'>[/color]
<script type="text/javascript" src="explain.js"></script>
[color=red]</td>
</tr>[/color]
</table>");
</script>
[color=pink]</body>[/color]
</html>[/CODE]

I have added head (in orange), title (in purple) and body (in pink) tags, which you should always include in a HTML/XHTML document.

The bit in green I have moved out of the document.write() function.

The language abitutary in the script tag shold not be used. Use <script type="text/javascript" src="explain.js"></script> including the src abitutary if neccessary.

The two tags in red I have swapped round.

Try to keep your code more organised, and take into account what a user with javascript disabled will see.

Neil
Copy linkTweet thisAlerts:
@mr_javaauthorAug 12.2004 — Thanks for ur correction Neil,

but I don't know why u move some of the TABLE out of document.write() funtion ?

it's just the question wether a .js file can be embedded into a document.write() function, and the .js file contains another document.write() function.


Here is the HTML code
-------------------------------------------------------------------


[SIZE=2]

[COLOR=royalblue]<html>[/COLOR]

[COLOR=orangered]<head>[/COLOR][COLOR=orange]<title>[/COLOR]HELP ME![COLOR=orange]</title>[/COLOR][COLOR=orangered]<head>[/COLOR]

[COLOR=darkred]<body>[/COLOR]



[COLOR=seagreen]<script language = "javascript">[/COLOR]

[COLOR=sienna]document.write("<table width='750' border='5'> <tr><td height='74'><script type='text/javascript' src=explain.js></script></td></tr></table>");[/COLOR]

[COLOR=seagreen]</script>[/COLOR]



[COLOR=darkred]</body>[/COLOR]

[COLOR=royalblue]</html>[/COLOR]

[/SIZE]


Here is the explain.js
-------------------------------------------------------------------


document.write('WHO CAN HELP ME');
Copy linkTweet thisAlerts:
@Daniel_TAug 12.2004 — From the looks of it, that would cause it to erase all page content and then, when all is said and done, all the page would say is "WHO CAN HELP ME" and then the table closing tags, since JavaScript must erase all page content before using document.write()
Copy linkTweet thisAlerts:
@PittimannAug 12.2004 — Hi!it's just the question wether a .js file can be embedded into a document.write() function, and the .js file contains another document.write() function.[/QUOTE]What you want is possible, but it would be much easier to handle things in a different way. And one of these ways would be neil9999's suggestion.

Going away from your original question, I would suggest that you do the following:

<html>

<head><title>HELP ME!</title>

<script type='text/javascript' src=explain.js></script>

<head>

<body>

<script language = "javascript">

document.write("<table width='750' border='5'><tr><td height='74'>"+helpVar+"</td></tr><table>");

document.close();

</script>

</body>

</html>

Your explain.js would contain this:

var helpVar='WHO CAN HELP ME';

Cheers - Pit
Copy linkTweet thisAlerts:
@neil9999Aug 12.2004 — Try this:

[code=php]<html>
<head><title>HELP ME!</title>
</head>

<body>

<script language = "javascript">
document.write("<table width="750" border="5"> <tr><td height="74"><script type="text/javascript" src="explain.js"></script></td></tr></table>");
</script>

</body>
</html>[/code]


You must put a before all ' or " or /

Neil

Edit:-- Pit you beat me!
Copy linkTweet thisAlerts:
@mr_javaauthorAug 12.2004 — Thank u all,Daniel T,Pittimann and Neil

I've tried Neil's example, but it doesn't work ?

Pittimann: the example you gave me run correctly. In recent days I've been dealing with a webpage encrypt plug-in, the content in the document.write() in the html file is active, so I should not know the content of the .js file ? Is there any other ways to solve the problem ? ? ?
Copy linkTweet thisAlerts:
@neil9999Aug 12.2004 — [i]Originally posted by mr.java [/i]

[B]I've tried Neil's example, but it doesn't work ?

[/B]
[/QUOTE]


The forum has removed some characters from my code. Click the 'Quote' button below my last post and copy the code from there.

Neil
Copy linkTweet thisAlerts:
@neil9999Aug 12.2004 — On second thoughts, attatched is the code.

Neil

[upl-file uuid=e25e5aee-1ffd-44be-ad1d-09010483c42a size=290B]docwriteexfile.txt[/upl-file]
Copy linkTweet thisAlerts:
@PittimannAug 12.2004 — Hi!I should not know the content of the .js file [/QUOTE]If you want the code to run without errors, you should know the content.Originally posted by Neil:

Pit you beat me![/QUOTE]
That was not at all my intention. :p

Greetz - Pit
Copy linkTweet thisAlerts:
@neil9999Aug 12.2004 — If you don't know the contents of the JS file, why you including it in your webpage? What if it's creator changes it so it isnt a document.write statement?

Neil
×

Success!

Help @mr_java spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...