...

View Full Version : Code only returns my div sporadic



phara0h
04-07-2006, 10:26 AM
My script failes to execute all lines of code sporadic.

My situation:
I am trying to develop an dynamic solution to microsofts new update to IE6, where all flash objects will need activation to remove an border. I develop an CMS solution so the script needs to be as dynamic as possible.

The goals:
1. I need to load the external script at runtime.
2. I need to be able to check if the file has been loaded.
3. I need to output an div
4. I need to use DOM to append children to that div.

The problem:
When using this with IE I only sporadic get it to display the wanted text in this test.

The suspect:
I suspect it to be the document.writeln in the getContainer function in jsflash.js. I had a problem with IE not loading the external script before calling writeNewDivWithContent so I added the pausecomp function to make it wait a little.

The code:
Sourceview: http://demo.siteman.no/jsflash/kilde.php
The testscript: (Refresh this multiple times in IE and it will only display the wanted text sporadic.
http://demo.siteman.no/jsflash/test_jsflash.php

The code:
test_jsflash.php:


<html>
<head>
</head>

<body>
<script language="Javascript" type="text/javascript">
if(window.jsflash_is_loaded){

}
else {
var skript = document.createElement('script');
skript.setAttribute('src','jsflash.js');
skript.setAttribute('type','text/javascript');
document.getElementsByTagName("head")[0].appendChild(skript);
}

function pausecomp(millis)
{
date = new Date();
var curDate = null;

do { var curDate = new Date(); }
while(curDate-date < millis);
}

pausecomp(150);
</script>
<script language="Javascript" type="text/javascript">
writeNewDivWithContent('testbox','Text to display');
</script>
</body>
</html>



jsflash.js:


var jsflash_is_loaded = true;

function writeNewDivWithContent(id,text){
newid = CreateContainer(id,text);
var container = document.getElementById(newid);
container.appendChild(document.createTextNode(text));

}

/*
Checks for existance of this id in document, and prints a div with a uniqe id.
*/
function CreateContainer(ContainerID){

if(document.getElementById(ContainerID)){
return CreateContainer(ContainerID + "_1");
}
else {
document.writeln('<div id="' + ContainerID + '"></div>');
return ContainerID;
}

}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum