#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    a cubicle in Rochester NY
    Posts
    82
    Rep Power
    13

    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
    Last edited by CrystalSilence; August 6th, 2001 at 01:19 PM.
    ---,------'---@----,------'---
    Let's put the fun back
    in dysfunctional.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2001
    Location
    Toronto, Ontario, Canada
    Posts
    631
    Rep Power
    13
    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>
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    a cubicle in Rochester NY
    Posts
    82
    Rep Power
    13
    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!
    ---,------'---@----,------'---
    Let's put the fun back
    in dysfunctional.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2001
    Location
    Toronto, Ontario, Canada
    Posts
    631
    Rep Power
    13
    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
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    a cubicle in Rochester NY
    Posts
    82
    Rep Power
    13
    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
    ---,------'---@----,------'---
    Let's put the fun back
    in dysfunctional.
  10. #6
  11. No Profile Picture
    Seņor Member
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2000
    Posts
    1,157
    Rep Power
    37
    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.
    Last edited by pieux; August 7th, 2001 at 08:47 AM.
    Michael
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    a cubicle in Rochester NY
    Posts
    82
    Rep Power
    13

    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.
    ---,------'---@----,------'---
    Let's put the fun back
    in dysfunctional.
  14. #8
  15. No Profile Picture
    Seņor Member
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2000
    Posts
    1,157
    Rep Power
    37

    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.
    Michael

IMN logo majestic logo threadwatch logo seochat tools logo