Submit Your Article Forum Rules

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: JavaScript Help

  1. #1
    Senior Member Dragonsi's Avatar
    Join Date
    Dec 2003
    Posts
    343

    JavaScript Help

    I am trying to get some JavaScript to work on a clients site ( www.1stopentertainments.co.uk ). The code in question is related to the animated gif at the top of the right hand column (Millenium Casinos).

    The reason for using JS is because the client wishes to change this banner every few months and updated about 250 pages each time is not fun. So by using a JS file which contains the banner location and destination URL, updating this file will change the whole site.

    Here is the JS file in question:

    var clicked=""
    var gtype=".gif"
    var selstate="_over"
    if (typeof(loc)=="undefined" || loc==""){
    var loc=""
    if (document.body&&document.body.innerHTML){
    var tt = document.body.innerHTML.toLowerCase();
    var last = tt.indexOf("banner01.js\"");
    if (last>0){
    var first = tt.lastIndexOf("\"", last);
    if (first>0 && first<last) loc = document.body.innerHTML.substr(first+1,last-first-1);
    }
    }
    }

    document.write("<table border=\"2\" cellspacing=\"0\" cellpadding=\"0\"><tr>");
    tr(false);
    writeButton(loc+"","http://millenniumcasinos.co.uk/millcas/index.htm","banner01",125,125,"A Real casino but you gamble just for fun","_blank",0);
    tr(true);
    document.write("</tr></table>")
    loc="";

    function tr(b){if (b) document.write("<tr>");else document.write("</tr>");}

    function turn_over(name) {
    if (document.images != null && clicked != name) {
    document[name].src = document[name].src;
    }
    }

    function turn_off(name) {
    if (document.images != null && clicked != name) {
    document[name].src = document[name].src;
    }
    }

    function reg(gname,name)
    {
    if (document.images)
    {
    document[name] = new Image();
    document[name].src = loc+gname+gtype;
    document[name] = new Image();
    document[name].src = loc+gname+gtype;
    }
    }

    function evs(name){ return " onmouseover=\"turn_over('"+ name + "')\" onmouseout=\"turn_off('"+ name + "')\""}

    function writeButton(urld, url, name, w, h, alt, target, hsp)
    {
    gname = name;
    while(typeof(document[name])!="undefined") name += "x";
    reg(gname, name);
    tr(true);
    document.write("<td>");
    if (alt != "") alt = " alt=\"" + alt + "\"";
    if (target != "") target = " target=\"" + target + "\"";
    if (w > 0) w = " width=\""+w+"\""; else w = "";
    if (h > 0) h = " height=\""+h+"\""; else h = "";
    if (url != "") url = " href=\"" + url + "\"";

    document.write("<a " + url + evs(name) + target + ">");

    if (hsp == -1) hsp =" align=\"right\"";
    else if (hsp > 0) hsp = " hspace=\""+hsp+"\"";
    else hsp = "";

    document.write("<img src=\""+loc+gname+gtype+"\" name=\"" + name + "\"" + w + h + alt + hsp + " border=\"0\" /></a></td>");
    tr(false);
    }
    The script is working on all pages while testing off-line but once on-line, the script is only working for HTML files in the root directory and not any pages which are under folders.

    e.g.
    Working page = www.1stopentertainments.co.uk/corparate.htm

    Not working =
    http://www.1stopentertainments.co.uk...olio/index.htm

    Any suggestions please...?
    www.westwalesweb.com
    Website development & ICT solutions.

  2. #2
    Dragonsi,
    slightly off the path here but could you not use an include file
    < !--#include file="js_stuff.htm"-- >

    The answer to your question;
    you may want to check your path as to where the js is refering to for the gif file if your are in a sub directory them the file path will require updating

    a single include file again would be a reasonable solution here..

    MM
    M0rtyM0use

    Simply Rugby

  3. #3
    Senior Member Dragonsi's Avatar
    Join Date
    Dec 2003
    Posts
    343
    Sorry, I should of mentioned.... when I called the Js file from a page within a folder, I did add the appropiate '../' or '../../' to the Js file address. As I said, I can get everything working off-line, it's just not happening online.

    In fact, if you view the source for a page within a directory ( http://www.1stopentertainments.co.uk...olio/index.htm ), the line of code which calls the JS file is missing......(should be there about 6 lines from bottom) >> What's all that about.....?

    Can you please expand apon your <includes> code, Java is still very new to me. The code I used in the example above is used in the same site to call up the main navigation on each page. That code works fine on any page in any folder.
    www.westwalesweb.com
    Website development & ICT solutions.

  4. #4
    Dragonsi,
    to be honest the "include" file is just another way to do what your doing on the index page however using an include file would solve your missing js code!

    where you have:::::



    [img]../../images/page/9.jpg[/img]</p>


    [img]../../images/page/7.jpg[/img]</p>


    [img]../../images/page/10.jpg[/img]</p>


    [img]../../images/page/square.gif[/img]</p>

    if you copy the above into a .htm file and place that in the root directory for example http://...../right_menu.htm

    NB: you do not need to have <html> etc at the top of the document

    will suffice.
    Then replace the above code in each page with


    This will use the same code on each page and allows you to avoid using all the ../ etc and if you want to make any changes then you ujust edit this one bit of code

    hope that expliain things and solves your problem

    MM
    M0rtyM0use

    Simply Rugby

  5. #5
    I do this sort of thing all the time.

    Use an absolute path to your javascript file and to the images the javascript references.

    An absolute path is like:
    http://www.domain.com/art/image.gif

    it looks like you are referencing relatives paths like:
    ../art/image.gif

    This should solve the problem since the script only seems to be bombing out on your live site. This will also allow the script to work in IE 5.1 for the mac.

  6. #6
    Using an absolute path would also do the trick but as this need to be updated every so often an include file in my opinion would be the better route to go, although like i say this is just an opinion...

    MM
    M0rtyM0use

    Simply Rugby

  7. #7
    Senior Member Dragonsi's Avatar
    Join Date
    Dec 2003
    Posts
    343
    Thanks everyone, I'll give you suggestions a go when I have a chance to work on that project again, will be mid week, I'll let you know how I get on...
    www.westwalesweb.com
    Website development & ICT solutions.

  8. #8
    Senior Member Dragonsi's Avatar
    Join Date
    Dec 2003
    Posts
    343
    Here's an update:

    Due to my busy work load at present, I decided on this occasion just to insert a normal HTML

    <a href="http://millenniumcasinos.co.uk/millcas/index.htm" target="_blank"><img src="banners/banner01.gif" blar blar..
    So I inserted this into every page (about 250), uploaded and tested.... guess what....

    The same problem as before.... any page located in a folder and not the root, does not display the gif, dispite adding the relavent '../' or '../../' before the image url.

    What the hell is going on, everything works fine off-line and I've done this a millian times before with no glitches....?

    Is this happening for everyone or just me....?
    www.westwalesweb.com
    Website development & ICT solutions.

  9. #9
    Dragonsi,
    on page http://www.1stopentertainments.co.uk...ands/index.htm

    the code should read....
    the image src should be the only bit you need to change if you want to dbl check you code to match...

    <table width="125" border="1" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
    <tr>
    <td>[img]../../banners/banner01.gif[/img]</td>
    </tr>
    </table>

    hope this helps
    MM
    M0rtyM0use

    Simply Rugby

  10. #10
    Senior Member Dragonsi's Avatar
    Join Date
    Dec 2003
    Posts
    343
    I've cracked it, I now know what is happening.. Many of you out there must be thinking, what is this guy on - I can see the banner....

    Well - the problem all alone has been my proxy server and newley installed Norton Personnal Firewall 2004 - They both have 'Banner Blockers'....

    After some invetigating, I discovered that because I called the graphic 'banner01.gif' and stored it in a folder called '/banners/' - the banner blocking software was cutting the code from my browser....

    All I need to do is change the folder name and file name, replace my original JavaScript and it should work...... This has been a painful leason......

    Something to concider when designing a website is that more and more users are using pop-up & banner blockers...... Choose you file names carefully....
    www.westwalesweb.com
    Website development & ICT solutions.

Page 1 of 2 12 LastLast

Similar Threads

  1. JavaScript Uses
    By jimmy03 in forum Search Engine Optimization Forum
    Replies: 2
    Last Post: 05-26-2009, 02:50 PM
  2. AJAX and javascript calling javascript
    By krnl in forum Web Programming Discussion Forum
    Replies: 14
    Last Post: 11-18-2007, 10:00 AM
  3. Javascript + RSS + RSS = ?
    By ofoglada in forum Web Programming Discussion Forum
    Replies: 6
    Last Post: 02-05-2006, 05:33 AM
  4. XP SP2, IE and Javascript
    By ChrisBowd in forum Graphics & Design Discussion Forum
    Replies: 1
    Last Post: 08-26-2004, 07:23 AM
  5. Javascript and php
    By icb01co2 in forum Web Programming Discussion Forum
    Replies: 1
    Last Post: 08-09-2004, 10:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •