javascript and netscape

Status
Not open for further replies.

tonyg_2

Wise, Aged Ars Veteran
155
two questions I think:
1) Can you link javascript files like you can C header files? I don't see why not. Just call a URL from javascript.

2) Internet explorer allows me to create an entirely dynamic page using javascript, right down to the script tags. Netscape will do everything, but pukes when I try to feed it script tags at any point. It either prints everything except the script tags, or chokes on the page entirely. Any thoughts on how to get around this? I do need to keep the page entirely generated by javascript: no static base page.

thanx a bunch
 

tonyg_2

Wise, Aged Ars Veteran
155
yeah, I'm trying to create the script tags dynamically. Also, my other question was how to call js files from within js files, kinda like the #include in C. So far I have found no documenetation on that. I don't see why it would not be a feature, but if it is not, I consider that a HUGE oversight in the creation of this language.

But more important is the dyanmic script tags. I am generating the entire website from a single javascript program. There are a few types of pages, and all can be created using three similar functions. It it just much simpler that way.
 

Prototyped

Ars Legatus Legionis
11,126
Try the link tag (from within HTML; I have no idea if JavaScript even supports #include-style inclusion for other JavaScript files).

For one thing, JavaScript doesn't have a preprocessor like languages such as C and C++ do. (It's the preprocessor, not the compiler, that deals with inclusion.)

<span style="margin-left: 50px"><tt>>link rel="Script" type="text/javascript" href="</tt>whatever<tt>.js" /></tt></span>

Edit: Try this tip:

http://developer.irt.org/script/63.htm

Essentially, split up the 'script' tag you're writing.

( http://www.irt.org/ is one of my favorite web development resource sites.)

[This message was edited by Prototyped on January 05, 2002 at 15:08.]
 

Nugar

Ars Scholae Palatinae
952
What I've been doing lately is linking just one js file to every html file I do at any given site. I call it jsloader.js. And from it, I call any other external file I need, including css. And just as well, I do a browser check and load a different css for each.

The contents of my jsloader.js is something like:

code:<HR>
Code:
 document.write('<script language=JavaScript src=/main/js/detect.js></script>') 
document.write('<script language=JavaScript src=/main/js/main.js></script>') 
document.write('<script language=JavaScript src=/main/js/content.js></script>') 
document.write('<script language=JavaScript src=/main/js/alttxt.js></script>')

So if I need any new js file, I just add it to jsloader and bingo! there it is, just the same as having a central css file :)

hope this help

Nugar
 

tonyg_2

Wise, Aged Ars Veteran
155
One thing I tried is to print the script source to the browser before anything else (even <HTML> ), which kinda works. (remember: internet explorer will do anything I want. Netscape doesn't want to print stuff properly). Although netscape doesn't physically print the script tags to HTML for use later, it *does* allow me to do dynamic content creation for that one page. But if I reload, I'm screwed, because it reloads the HTML from memory, which does not include any <script> tags, since netscape refuses to print them.

I like the idea of the jsloader. I'm not sure what or how to use the link ref thing. could you elaborate?

and the rest of you: I know how to link javascript into HTML. that is not the problem.
 

Prototyped

Ars Legatus Legionis
11,126
<tt><link></tt> is just an HTML tag. It's usable in place of <tt><script src="</tt>whatever<tt>.js"></tt> -- but it can be used to 'include' a whole bunch of objects, scripts being one such.

Netscape will see the intact <tt><script></tt> tag and barf, trying to execute stuff it sees 'within' the innermost script block this creates. However, if you split this up, e.g. <tt>'<scr' + 'ipt>'</tt>, this doesn't occur. (Blame it on Netscape 4's less-than-stellar parser.)
 
that's a great idea Nugar, I just implemented that for the Arsware design I'm working on. That way I can easily manage the addition of CSS's and scripts in one file.

Edit: I just realized that people who have java disabled would get unformatted content now, I think I'd be better off with a server side include.

[This message was edited by 8-Track on January 07, 2002 at 07:48.]
 

tonyg_2

Wise, Aged Ars Veteran
155
not true... I already tried some tricks like that. I used to have problems closing scripts, so I would break the </script> up to <scr + ipt>.

So I tried that with the start... I even tried implementing either side on different functions:

function1(){
document.write('<scr');
}
function2(){
document.write('ipt src="">');
...
}

but still, netscape refuses to publish the script tag.
I will try the link tag after work.

It shouldn't matter, but I am using netscape 4.5 - 4.8 for linux. I can't imagine that windows and mac versions of netscape would respond any differently, but stranger things have happened...
 

Nugar

Ars Scholae Palatinae
952
Hmm, I hadn't think about the disabled javascript...

A SSI would be probably better, but I'm thinking that anyway I'm loading my CSS by browser using a javascript too. My knowledge of SSI ia just about inluding a footer, header or whatever.





Anyone has any statistics about how many people disable javascript while browsing?





BTW, my js loader now looks someting like:









code:<hr>
Code:
 /**********************************************************************************/
// JSLoader
// Humberto Olarte
// Jan 06, 2002
//
// This scripts loads other useful scripts and css on-demand. This approach is provided
// in an attempt to centralize site management
//
/**********************************************************************************/
// To use CSS loader, set the cssLoader to 1
// This script requires that you also set browserDetect to 1
/* The scripts then loads:
		/main/styles/main_win.css for MSIE  and NN6 and browsers other than NN4 or Mac based
		/main/styles/main_nets4.css for NN4
		/main/styles/main_mac.css for MSIE on Macs
		/main/styles/nets4_mac.css for NN4 on Macs
*/ 
var cssLoader = 1;<p>// To load a browser detection library, set browserDetect to 1
var browserDetect  = 1;<p>// To load a library for alt text effects, set altText to 1
// This library also loads contents.js where the alt text is located.<p>var altText = 1;<p>/*
To load a popup library, set popup to 1
Use Example for Popup script:
 <a href="/about_us/nut_tables/nt_vanilla.html" onclick="NewWindow(this.href,'name','320','340','yes');return false;">
 <img src="/main/images/facts_vanilla.jpg" width="160" height="140" border="0">
 Vanilla</a>
*/<p>var popup = 1;<p>// To load image rollover library, set rollOver to 1<p>var rollOver = 1;<p>// Loading routines:<p>// Browser detection loader<p>if (browserDetect = 1){ 
document.write('<script language=JavaScript src=/main/js/detect.js></script>') 
}<p>// Load cssLoader<p>if (cssLoader = 1){ 
document.write('<script language=JavaScript src=/main/js/cssloader.js></script>') 
}<p>
// Alternative text loader<p>if (altText = 1){ 
document.write('<script language=JavaScript src=/main/js/alttxt.js></script>')
document.write('<script language=JavaScript src=/main/js/content.js></script>') 
}<p>//Popup library loader<p>if (popup = 1){ 
document.write('<script language=JavaScript src=/main/js/popup.js></script>') 
}<p>// Rollover library loader<p>if (rollOver = 1){ 
document.write('<script language=JavaScript src=/main/js/rollover.js></script>') 
}


So... where can I get info on how to do this with SSI? Is it doable?





Another comment: NN4 seems to choke on this, but we (as in my partner and me) have decided to let it go as of Jan 2002, so at our shop NN4 is officially in the same status as NN3 -- :) --





Nugar
 
Status
Not open for further replies.