The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Web Design
> JavaScript Development
|
external javascripts
Discuss external javascripts in the JavaScript Development forum on Dev Shed. external javascripts JavaScript Development forum discussing JavaScript and DHTML, AJAX, and issues such as coding cross-browser JavaScript.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

August 6th, 2001, 11:33 AM
|
|
Contributing User
|
|
Join Date: Jun 2001
Location: a cubicle in Rochester NY
Posts: 82
Time spent in forums: < 1 sec
Reputation Power: 12
|
|
|
external javascripts
OK, been doing some research and here's what I know I have to do:
I have these 2 external javascript files; both of them are trying to use window.onload.
Since I am a newbie, I don't know how to combine them to make them stop conflicting; I know that somehow I have to put the window.onload functions into the <body> tag seperated by semicolons, but I'm not sure how to do this. Here's the script code:
popup.js
staticlogo.js
THANKS!
 CS
__________________
---,------'---@----,------'---
Let's put the fun back
in dysfunctional.
Last edited by CrystalSilence : August 6th, 2001 at 01:19 PM.
|

August 6th, 2001, 06:18 PM
|
|
Contributing User
|
|
Join Date: Jun 2001
Location: Toronto, Ontario, Canada
Posts: 631
Time spent in forums: 7 m 19 sec
Reputation Power: 12
|
|
|
I dont understand what you're saying, but this may help
<script language="javascript" src="src"></script>
<script language="javascript" src="src2"></script>
<body onUnLoad="function_from_either_script();function_from_either_script();">
...
</body>
|

August 7th, 2001, 07:09 AM
|
|
Contributing User
|
|
Join Date: Jun 2001
Location: a cubicle in Rochester NY
Posts: 82
Time spent in forums: < 1 sec
Reputation Power: 12
|
|
well the first script has functions that look like this:
if (ns4)
window.onload=createlogo;
else if (ie4)
crosslogo=document.all.logo
else if (ns6)
crosslogo=document.getElementById("logons6")
and the other one looks like this:
window.onload = new Function('pMenu.update()');
window.onresize = new Function('ns4BugCheck(); pMenu.position()');
I know that they are conflicting because they are both trying to use window.onload, but when i try to take them out of the script and use <body onload=function();otherfunction()> I still get errors, and nothing works.
Thanks for helping!
|

August 7th, 2001, 07:54 AM
|
|
Contributing User
|
|
Join Date: Jun 2001
Location: Toronto, Ontario, Canada
Posts: 631
Time spent in forums: 7 m 19 sec
Reputation Power: 12
|
|
Having 2 onloads creates errors, and with <body onLoad="">, you have to put the JS inside the " ".
<body onLoad="createlogo();new Function('pMenu.update()');">
In the createlogo function, if it's not ns4, do nothing... I don't know if you can (probably could) put this:
<body onLoad="if(ns4)createlogo();new Function('pMenu.update()');">
Hope this helps 
|

August 7th, 2001, 08:12 AM
|
|
Contributing User
|
|
Join Date: Jun 2001
Location: a cubicle in Rochester NY
Posts: 82
Time spent in forums: < 1 sec
Reputation Power: 12
|
|
no luck.
I get a message saying ns4 is undefined.
I'll keep playing with it... or maybe find another way to do this?
Thanks so much for helping!
 CS
|

August 7th, 2001, 08:37 AM
|
|
|
Well, when you get this message, it should also tell you in what file and on what line number the error occurs. If you could provide that, that would be really helpful.
Barring that, where is ns4 being declared in the script? If you are getting a message that it's undefined, that probably means that either you have a syntax error (missing a semicolon or something somewhere and it's not seeing your definition/declaration of ns4) or you aren't actually defining the variable.
UPDATE: OK, I decided to stop being lazy and search your files for myself... staticlogo contains a declaration for ns4 and popup contains a declaration for isNS4. I say, delete both of these sections, create a third .js file (maybe call it detect.js) and place the following in that file:
PHP Code:
function browser() {
if (document.layers) { // Netscape 4.x
return "N";
} else if (document.all) { // Internet Explorer 4.x +
return "IE";
} else if ((document.getElementById) && (!(document.all))) { // Netscape 6, etc.
return "DOM";
}
}
With this code, what you want to do is modify the other code to call this function. For example, instead of doing "if (isN4)", you would do "if (browser() == 'N')". The reasoning for this is you centralize the object detection so you can add more at a later date without having to rewrite your code. Secondarily, you also benefit from forcing yourself to check a value returned by a function, rather than relying on the boolean setting of a variable that could possibly be overwritten inadvertantly by some other script.
__________________
 Michael
Last edited by pieux : August 7th, 2001 at 08:47 AM.
|

August 7th, 2001, 08:51 AM
|
|
Contributing User
|
|
Join Date: Jun 2001
Location: a cubicle in Rochester NY
Posts: 82
Time spent in forums: < 1 sec
Reputation Power: 12
|
|
|
new code- i'll try again
ok, modified the code a bit: still getting an error but only one...
body tag looks like this:
<BODY onLoad="new Function('pMenu.update()');if(document.layers)createlogo();insertimage();">
popup menu script stays the same as i had stated earlier.
The error says: Line 52 (the body onLoad line) object expected.
here's the new logo script:
if (document.images)
var logowidth=72
var logoheight=36
var staticlogo=new Image(logowidth,logoheight)
staticlogo.src="cnbweblogo.gif"
var logolink="http://www.cnbank.com"
var alttext="Canandaigua National Bank"
var fadeintoview=1
var visibleduration=0
function regenerate(){
window.location.reload()
}
function regenerate2(){
if (document.layers)
setTimeout("window.onresize=regenerate",400)
}
var fadeset=''
if (fadeintoview)
fadeset="filter:alpha(opacity=0)"
if (document.all)
document.write('<span id="logo" style="'+fadeset+';position:absolute;top:100;width:'+staticlogo.width+';height:'+staticlogo.height+'"></span>')
function bringintoview(){
if (logo.filters.alpha.opacity<=95)
logo.filters.alpha.opacity+=5
else{
clearInterval(viewit)
if (visibleduration!=0)
setTimeout("logo.style.visibility='hidden'",visibleduration*1000)
}
}
function createlogo(){
staticimage=new Layer(100)
staticimage.left=-300
staticimage.top=120
staticimage.document.write('<a href="'+logolink+'"><img src="'+staticlogo.src+'" border=0 alt="'+alttext+'"></a>')
staticimage.document.close()
staticimage.visibility="show"
regenerate2()
staticitns()
}
if (document.all){
w=document.body.clientWidth-logo.style.pixelWidth-5
h=document.body.clientHeight-logo.style.pixelHeight-5
logo.style.left=w
logo.style.top=h
}
function logoit(){
var w2=document.body.scrollLeft+w
var h2=document.body.scrollTop+h
logo.style.left=w2
logo.style.top=h2
}
function logoit2(){
staticimage.left=pageXOffset+window.innerWidth-staticimage.document.width-15
staticimage.top=pageYOffset+window.innerHeight-staticimage.document.height
}
function insertimage(){
logo.innerHTML='<a href="'+logolink+'"><img src="'+staticlogo.src+'" border=0 alt="'+alttext+'"></a>'
if (fadeintoview)
viewit=setInterval("bringintoview()",100)
else{
if (visibleduration!=0)
setTimeout("logo.style.visibility='hidden'",visibleduration*1000)
}
}
if (document.all){
window.onscroll=logoit
window.onresize=new Function("window.location.reload()")
}
Last edited by CrystalSilence : August 7th, 2001 at 10:24 AM.
|

August 7th, 2001, 04:18 PM
|
|
|
You probably don't want to use that code, because it explicitly only works for browsers that support the document.all DOM (Document Object Model). Meaning, it's probably only gonna work in IE.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|