/    Sign up×
Community /Pin to ProfileBookmark

Execution order problem in ie

<script>
document.write(‘<table border=”1″ cellspacing=”0″ cellpadding=”0″ align=”center”><tr></td></tr><tr><td>’);
document.write(‘<script language=”JavaScript” src=”1.js”></script>‘);
document.write(‘</td></tr></table><br>’);
</script>

1.js contents:
document.write(‘hello’);


—–

As you can see the contents of 1.js is written out after the table in ie.
Im looking for a way to solve this. Is there a way to force ie to write 1.js inside the table.

I can’t use frames in the current enviroment.

Thanks in advance.

to post a comment
JavaScript

11 Comments(s)

Copy linkTweet thisAlerts:
@KorFeb 09.2006 — document.write is not a dynamic method. Use DOM methods or even innerHTML nonstandard method to creeate/change dynamically elements/attributes on the page:

As it is your problem is vague...

Can you detail your problem, maybe we can find a short and proper solution... First at all, do you really need javascript to do that? Whenever you may use simple HTML code, use it.
Copy linkTweet thisAlerts:
@stenmarkauthorFeb 09.2006 — Thanks. Can you give me an example how you can solve the above issue with DOM methods or innerHTML...?

Thanks again.
Copy linkTweet thisAlerts:
@KorFeb 09.2006 — As I said... Once again...

Can you detail your problem, maybe we can find a short and proper solution. What you want to do. In ordinary words...
Copy linkTweet thisAlerts:
@stenmarkauthorFeb 17.2006 — Ok. I would like to write out a function inside a table. This function consist of external js files. My problem is that the function is written out after the table...Everything is written out using document.write...

Thanks in advance.
Copy linkTweet thisAlerts:
@Orc_ScorcherFeb 17.2006 — Try the following:<i>
</i>&lt;script src="1.js"&gt;&lt;/script&gt;
&lt;script&gt;
document.write('&lt;table border="1" cellspacing="0" cellpadding="0" align="center"&gt;&lt;tr&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;');
writeIt();
document.write('&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br&gt;');
&lt;/script&gt;

1.js contents:
function writeIt() {
document.write('hello');
}
Copy linkTweet thisAlerts:
@KorFeb 17.2006 — your html table code is incorrect. A simple table should be

<table>

<tr>

<td>

</td>

</tr>

<tr>

<td>

</td>

</tr>

</table>

Watch out the tags
Copy linkTweet thisAlerts:
@stenmarkauthorFeb 17.2006 — thanks...however i relized my situation is this:

<script>

function writeIt() {

document.writeln("<script language="JavaScript" src="1.js">");

document.writeln("</script>");

}

document.writeln("<script language="JavaScript">");

document.writeln(" document.write('<table border="1" cellspacing="0" cellpadding="0"><tr><td>');");

document.writeln(" writeIt();");

document.writeln(" document.write('</td></tr></table><br>');");

document.writeln("</script>");

</script>

1.js:

function writeIt2() {

document.write('hello');

}

I can't get this to work...thanks for your help...
Copy linkTweet thisAlerts:
@KorFeb 17.2006 — once again... You table is incorrect written. you have

<table>

[COLOR=Red]</td></tr>[/COLOR]

<tr><td>

</td></tr>

</table>

Remove the reds
Copy linkTweet thisAlerts:
@stenmarkauthorFeb 17.2006 — modified...still don't work....
Copy linkTweet thisAlerts:
@KorFeb 17.2006 — I should have used DOM instead of document.write():
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
onload = function(){
var root = document.getElementById('mydiv');
var oTab=cE('table'); var oTbo=cE('tbody'); var oTr=cE('tr'); var oTd=cE('td'); var oSc=cE('script'); var oBr=cE('br');
sA(oSc,['type','src'],['text/javascript','1.js']);
oTd.appendChild(oSc);oTr.appendChild(oTd);oTbo.appendChild(oTr);oTab.appendChild(oTbo);
sA(oTab,['border','cellSpacing','cellPadding'],['1','0','0']);
root.appendChild(oTab);
root.appendChild(oBr);
}
function cE(tag){
var obj =document.createElement(tag)
return obj;
}
function sA(obj,att,val){
for(var i=0;i<att.length;i++){
obj.setAttribute(att[i],val[i]);
}
}
</script>
</head>
<body>
<div id="mydiv"></div>
</body>
</html>
[/code]


But why so intricate writing and overwriting... What is you need, in fact?
Copy linkTweet thisAlerts:
@ScriptageFeb 17.2006 — Certainly not pretty but it works:

<div id="something"></div>

<script id="blank_script"></script>

<script>

document.write("<table><tr><td>header</td></tr><tr><td>");

blank_script.src = "1.js";

</script>

<script>

loadMe();

</script>

<script>

document.write("</td></tr><tr><td>footer</td></tr>");

</script>

Have the code in your external .js file in a function called loadMe();
×

Success!

Help @stenmark 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...