...

View Full Version : Need help getting two different funcion scripts withinin <HEAD> to operate



WebKunstler
07-28-2002, 07:20 AM
Howdy. I am primarily an artist/graphic designer with a severe tech bent, and I've been working/searching in vain for a way to get a client's website to contain: (1)a browser detect and "document.write('<link rel>)" function for its respective stylesheets, and, (2)the preload/swapImage script for its mouseover images within the <Head> elements--and have both of them function. The books I have place both these functions inside the <Head> elements (with the "onLoad" and "OnMouse-x" stuff within the Body), but I can find nothing that tells me how to get these guys to play together without one of 'em biting the dust..
The mouseover stuff is Dreamweaver 4's, and the browser detect is a combo from the "Teach Yourself Javascript in 24 hours" & the Osborne 3rd HTML Reference books. I feel like I'm probably missing a basic solution, but I sure haven't found it....Am I wanting the impossible?

I would appreciate any understanding you guys might be able to impart--am having difficulty finding any in either book...

THX

A1ien51
07-28-2002, 07:31 AM
see if this link helps you out:
http://www.javascriptkit.com/javatutors/multiplejava.shtml

WebKunstler
07-28-2002, 08:27 AM
I'd read that link prior to posting my question, but reread it completely--along with some other links I'd bookmarked from WebMomkey in hopes I'd missed something. Those scripts don't have an "OnLoad" furhter down in the Body--just the <span class="_"> tags (if necessary) at the appropriate points in copy.

Maybe I should create an "OnLoad"? I'll try that later this am--gettin' bleary-eyed.

oh--like your "location". cool.

joh6nn
07-28-2002, 08:53 AM
can we see the code you're working with? would make it easier for us to help you figure out where the problem is.

WebKunstler
07-28-2002, 01:31 PM
thanks,joh6nn. here's the browser detect/writeStyles script:

<script language="JavaScript">
<!--
function writeStyles()
{
if ((navigator.appVersion.charAt(0) >= "4")
|| (navigator.appVerions.charAt(0) >= "5")) {
if (navigator.appName == "Netscape")
browser="netscape";
else if (navigator.appName=="Microsoft Internet Explorer")
browser="ie";
else alert("This site requires a 4.0 or later browser.");
}
if (browser=="ie") {
document.write('<link rel="stylesheet" type="text/css" href="iestyle.css">');
}
if (browser=="netscape") {
document.write('<link rel="stylesheet" type="text/css" href="netstyle.css">');
}
//-->
</script>

there's no "onload" reference to this script within the <BODY> tags; just <span> elements where needed...

was working fine (with <link rel> line in the head) til i saw how differently the browsers interp'ed the pixel sizes and decided i wanted them to look as similar as possible...(yeah, i know, "stupid designer!")

WebKunstler
07-28-2002, 02:13 PM
just realized i could attach one of the pages resaved as text file--Been at it a little too long/gettin sloppy...

tried various ways to marry the first function to the following original page (and similar),+ 2 stylesheets to have just one site: A) as 2 separate functions within <script> tags; B) using a "<script src>" line with corresponding .js files & folder; C) combining the 2 functions coupled with changing their order--not smart when really tired & frustrated; D) variations of the aforementioned, and other desperate measures that make me realize i'm trying to teach myself too many things too quickly...

I've used simpler mouseover/preload code before, but I've had no probs with Dreamwvr code + some hand editing til now...

Seems needless to make separate sites, but been lookin at it too long to see clearly now

thanks!

joh6nn
07-29-2002, 06:23 AM
i made a couple of changes to your code, mostly just adding { }'s to your if-else clauses, to make it easier to read. i also added a line that actually calls your function, because that didn't seem to be present. if you still have problems, i'd say to post a link to the site, or attach a file with all the code in it, so we can get a look at the whole page.

i know that there's a way to do a sort of browser detect within a style sheet ( it relies upon the peculiarities of browsers ), but i'm not real familiar with it. here's an article on the subject:
http://www.evolt.org/article/Assigning_browser_specific_styles/17/14732/index.html

good luck.


ps: are you in germany?

WebKunstler
07-29-2002, 07:40 AM
i read through your reply, but couldn't find a file with the changes you talked about anywhere (my original browser-detect post looks the same as the copy on my hard drive)...would you mind posting it in another reply so I could see how you did what you did, and see how it works?
i am grateful for the trouble you've taken to reply--this has really had me going; and shown me that i'm gonna have to take a little more time with this. Learning on the fly and against deadline just ain't cuttin' it!

And, no, i'm not in germany, but the U.S. Memphis, TN, at present, but not for much longer. As to my German username, i was born in Germany and i'm Greek American....(!)

joh6nn
07-29-2002, 08:05 AM
sorry, thought i posted it, but i must've forgotten. here you go:

<script language="JavaScript"> <!--
function writeStyles() {
var style;
if ((navigator.appVersion.charAt(0) >= "4") || (navigator.appVerions.charAt(0) >= "5")) {
if (navigator.appName == "Netscape") {
style = "netstyle.css";
}
else if (navigator.appName=="Microsoft Internet Explorer") {
style = "iestyle.css";
}
else {
alert("This site requires a 4.0 or later browser.");
}
}
document.write('<link rel="stylesheet" type="text/css" href="' + style + '">');
}
//-->
</script>


i suggest you take a look at the article i linked to; it's probably a better solution to this.

WebKunstler
07-29-2002, 07:49 PM
thanks again, man.

i took a look at that article last night as soon as i read your reply post, but had too bookmark it so i could read with a rested brain--even then it did look like a better solution. i'll probably try to get these two scripts working together anyway just to find out what i wasn't doing --or doing wrong.

if you like, i'll post a link to my site when i've got it back up--kinda proud of it

WK



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum