Click to See Complete Forum and Search --> : Making document.write fire reliably onload in IE5
luvbytes
02-08-2003, 08:20 PM
I am developing reusable code for Web Pages, creating fixed portions of the page as objects ('scriptlets') contained in an external .js file. Each object is assigned a VARIABLE name. (Eg: VARIABLE="...A bunch of text that appears on every page blah blah blah etc...')
The page is constructed with a series of 'document.write(VARIABLE)' instructions embedded in the page in <script> tags, and positioned with tables and/or CSS.
These work fine on my local client machine, but when uploaded to the web, I notice that until the page has been refreshed and cached in the browser, they do not always 'fire' reliably, leaving occasional unpredictable 'bald' patches in the resulting pages. (And yes, the external .js script is loaded in the <HEAD> tags.)
I'm experimenting with 'onload' function, but anyone had experience of this problem and evolved a fireproof solution?
Ta,
'Luvbytes'
If I understand you correctly, you are using javascript to include the same content on all your pages, sort of like a footer? If so, I'd recommend using SSI or PHP to do this instead....Is that what you were doing with it?
luvbytes
02-08-2003, 09:15 PM
Thanks - appreciate the tip - but it doesn't solve the JScript issue. It's counter-intuitive to create a workaround in a completely different language. Especially since I don't write in either of them...Anyone out there who can help?
Originally posted by luvbytes
It's counter-intuitive to create a workaround in a completely different language.You didn't answer my question of if I had the right idea about what you were trying to do. If I did, using javascript to include parts of your page will make it so that those parts are non-accesable to 10% of web users who have javascript disabled.
Here are the recommend way of including content
PHP (rename pages to .php)
<?PHP
include ("footer.htm");
?>
SSI (rename pages to .shtml)
<!--#include file="footer.htm"-->
luvbytes
02-09-2003, 08:44 AM
Thanks again Pyro, and I promise I'll try these out - but but but I still need a JavaScript solution.
I can use Front Page includes, but these have scripting problems of their own, and rely on a co-operative server. The classical scriptlet technology for IE5 :
"<object height= '100' width='800' type = 'text/x-scriptlet' data= 'somefile.htm' ></object>";
suffers the same 'failure to fire reliably' syndrome.
The inclusion of a complete file seems like overkill for a single page element like a title or a graphic, and it doesn't, allow the element to interact with the page as flexibly, nor make it easy to edit - and the files proliferate.
Here's an example of the compactness of the document write approach:
<html><head><title>index</title>
<link rel='stylesheet' type='text/css' href='pagestyle.css'>
<script src='jscript.js'></script>
</head><body topmargin='10'><table border=0 cellpadding=2 cellspacing=0 width='75%'><tr><td colspan=4 width='100%'>
<script>W(LOGO)</script>
</td></tr><tr>
<td width='15%'align='middle'><script>W(ADDRESS)</script></td>
<td align='center' width='35%'><script>W(IMAGE1)</script></td>
<td align='center' width='35%'><script>W(IMAGE2)</script></td>
<td align='middle' width='15%'><script>W(IMAGE3)</script></td>
</tr><tr><td valign='top' align='right' width='15%'><script>W(MENU)</script></td>
<td align='center' colspan=2 width='70%'>
<iframe name='main' width=530 height=350 frameborder=0 src='home.htm'></iframe></td>
<td align='middle' valign='top' width='15%'><script>W(IMAGE4)</script></td>
</tr></table></body></html>
MENU, LOGO, IMAGE1 etc are all concatenated in the .js file.
The HTML page weighs in at 1Kb and the .js file at 3Kb (of course, you only have to cache the .js file once.). This gives sub 5 second load times - a consideration when only 3% of the UK has broadband.
Callous, I know, but (outside the USA), IE5-6 is the only game in town, so I always politely redirect unscripted browsers to surf elsewhere.
Come on, where have all the JavaScript guru's gone?
Originally posted by luvbytes
but but but I still need a JavaScript solution.I don't know why you would want to do this, but I can explain after I know exactly what you want. I'm assumbing that <script>W(ADDRESS)</script> is so that W(ADDRESS) can be a variable and you can chage it on all pages by only changing the javascript? Is that right?
Originally posted by luvbytes
The inclusion of a complete file seems like overkill for a single page element like a title or a graphicYou don't need to include a complete file. With either SSI or PHP you can include only one file, a bit of text, an image, etc.
Let me give you an example of the code you gave using PHP includes.
<html><head><title>index</title>
<link rel='stylesheet' type='text/css' href='pagestyle.css'>
<script src='jscript.js'></script>
</head><body topmargin='10'><table border=0 cellpadding=2 cellspacing=0 width='75%'><tr><td colspan=4 width='100%'>
<? include("yourlogo.gif") ?>
</td></tr><tr>
<td width='15%'align='middle'><? include("youraddress.txt") ?></td>
<td align='center' width='35%'><? include("yourimage.htm") ?></td>
<td align='center' width='35%'><? include("yourimage2.htm") ?></td>
<td align='middle' width='15%'><? include("yourimage3.htm") ?></td>
</tr><tr><td valign='top' align='right' width='15%'><? include("yourmenu.htm") ?></td>
<td align='center' colspan=2 width='70%'>
<iframe name='main' width=530 height=350 frameborder=0 src='home.htm'></iframe></td>
<td align='middle' valign='top' width='15%'><? include("yourimage4.htm") ?></td>
</tr></table></body></html>So, as you can see, you can include just an image, or a bit of text, etc. Although, there is no value in including an image like this. What you'd probably want to do is include a .htm file with this in the file...
yourimage.htm
<img src="your.gif" border="0">
Originally posted by luvbytes
Come on, where have all the JavaScript guru's gone?We're all still here. I'm just trying to show you a better way...
luvbytes
02-10-2003, 08:45 PM
Better way? - well different anyhow:I'd have create a complete new object for every one of these includes, instead of a set of variables in a single.js file. Here's the include approach:
include1.htm
include2.txt
include3.gif
etc...every one of these has to be fetched from the server as a separate operation, together with the file overheads
Now every file has to be assembled with 3 include statements.
If I elect to add or delete an include, I have to edit every assembled file.
I can do the same with a single line addition or rem an item out with //...and I don't have to install a server or run online to run initial testing either.
The includes approach is very useful for assembling one or two 'master' container files, but it still means resorting to a frame/iframe for variable content, and I want to move away from frame limitations.
JavaScript, anyone?
Why don't you post a link to the page, as you say it works sometimes, but not others...