JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 6th, 2001, 11:33 AM
CrystalSilence CrystalSilence is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: a cubicle in Rochester NY
Posts: 82 CrystalSilence User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
Send a message via AIM to CrystalSilence
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.

Reply With Quote
  #2  
Old August 6th, 2001, 06:18 PM
DJdrenaline DJdrenaline is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2001
Location: Toronto, Ontario, Canada
Posts: 631 DJdrenaline User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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>

Reply With Quote
  #3  
Old August 7th, 2001, 07:09 AM
CrystalSilence CrystalSilence is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: a cubicle in Rochester NY
Posts: 82 CrystalSilence User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
Send a message via AIM to CrystalSilence
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!

Reply With Quote
  #4  
Old August 7th, 2001, 07:54 AM
DJdrenaline DJdrenaline is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2001
Location: Toronto, Ontario, Canada
Posts: 631 DJdrenaline User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #5  
Old August 7th, 2001, 08:12 AM
CrystalSilence CrystalSilence is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: a cubicle in Rochester NY
Posts: 82 CrystalSilence User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
Send a message via AIM to CrystalSilence
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

Reply With Quote
  #6  
Old August 7th, 2001, 08:37 AM
pieux pieux is offline
Seņor Member
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2000
Posts: 1,157 pieux User rank is Sergeant Major (2000 - 5000 Reputation Level)pieux User rank is Sergeant Major (2000 - 5000 Reputation Level)pieux User rank is Sergeant Major (2000 - 5000 Reputation Level)pieux User rank is Sergeant Major (2000 - 5000 Reputation Level)pieux User rank is Sergeant Major (2000 - 5000 Reputation Level)pieux User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 h 23 m 35 sec
Reputation Power: 36
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.

Reply With Quote
  #7  
Old August 7th, 2001, 08:51 AM
CrystalSilence CrystalSilence is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: a cubicle in Rochester NY
Posts: 82 CrystalSilence User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
Send a message via AIM to CrystalSilence
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.

Reply With Quote
  #8  
Old August 7th, 2001, 04:18 PM
pieux pieux is offline
Seņor Member
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2000
Posts: 1,157 pieux User rank is Sergeant Major (2000 - 5000 Reputation Level)pieux User rank is Sergeant Major (2000 - 5000 Reputation Level)pieux User rank is Sergeant Major (2000 - 5000 Reputation Level)pieux User rank is Sergeant Major (2000 - 5000 Reputation Level)pieux User rank is Sergeant Major (2000 - 5000 Reputation Level)pieux User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 h 23 m 35 sec
Reputation Power: 36
Thumbs down

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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > external javascripts

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap