Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts

    how do you call an External Js file in html?

    Hi All,

    I am new to javascript and i have used a piece of code from a tutorial on the web and have saved it as ticker.js however i cannot get it to work in the html code here is the ticker code
    <code>
    <!--
    // please keep these lines on when you copy the source
    // made by: Nicolas - http://www.javascript-page.com

    var tags_before_clock = "";
    var tags_after_clock = "";
    var speed = 100;
    var speed2 = 2000;

    function initArray() {

    this.length = initArray.arguments.length;
    for (var i = 0; i < this.length; i++) {
    this[i] = initArray.arguments[i];
    }
    }

    var mymessage = new initArray(
    "Latest News: Site Updated 9 June 08",
    "New Store Added: Jamster - Misc - 8 June 08",
    "New Store Added: iTunes - Entertainment - 2 June 08",
    "New Store Added: Butlins - Misc - 2 June 08"
    );

    var mymessage2 = mymessage;
    var x = 0;
    var y = 0;

    if(navigator.appName == "Netscape") {
    document.write('<layer id="ticker"></layer><br>');
    }

    if (navigator.appVersion.indexOf("MSIE") != -1){
    document.write('<span id="ticker"></span><br>');
    }

    function upticker(){

    if (y > mymessage2.length - 1) {
    y = 0;
    setTimeout("upticker()",speed);
    }

    else{

    if (x > mymessage2[y].length) {
    mymessage = mymessage2[y];
    x = 0; y++;
    setTimeout("upticker()",speed2);
    }

    else {
    mymessage = mymessage2[y].substring(0,x++);
    setTimeout("upticker()",speed);
    }

    if(navigator.appName == "Netscape") {
    document.ticker.document.write(tags_before_clock+mymessage+tags_after_clock);
    document.ticker.document.close();
    }

    if (navigator.appVersion.indexOf("MSIE") != -1){
    ticker.innerHTML = tags_before_clock+mymessage+tags_after_clock;
    }
    }
    }

    setTimeout("upticker()",speed);
    //-->

    </code>

    and i have used <script language="JavaScript1.2" type="text/javascript" source="ticker.js"> to call it but nothing appears can anyone tell what im doing wrong

    thank you in advance
    Luke
    Last edited by LJackson; 06-11-2008 at 08:48 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,252
    Thanks
    203
    Thanked 2,557 Times in 2,535 Posts
    <script type="text/javascript" source= "ticker.js"> </script>

    I take it that ticker.js is in the same directory as your .html file.

    BTW, the time to say "thanks" is afterwards, not beforehand which gives the impression that you take other people's unpaid assistance for granted. Or as British politician Neil Kinnock put it, "Don't belch before you have had the meal." Prefer to use "please" beforehand and if you find a response helpful then you can use the "Thank You For This Post" button.

  • Users who have thanked Philip M for this post:

    LJackson (06-11-2008)

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts
    yeah it is in the same directory, and thank you for your code it works just as i wanted

    cheers
    Luke

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts
    is it possible to have parts of the ticker link to another site

    using the same code above,

    <code>
    var mymessage = new initArray(
    "Latest News: Site Updated 9 June 08",
    "New Store Added: Jamster - Misc - 8 June 08",
    "New Store Added: iTunes - Entertainment - 2 June 08",
    "New Store Added: Butlins - Misc - 2 June 08"
    );
    </code>
    is it possible to have Misc(in bold and green) link to a page in the same directory called Misc and is it possible to have the word misc appear in green font?


  •  

    Posting Permissions

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