Results 1 to 11 of 11

Thread: Javascript question

  1. #1
    Da Big Cheez of TCG Master Trainer
    Master Trainer
    Roarkiller's Avatar
    Join Date
    Jan 2001
    Location
    Singapore
    Posts
    7,588

    Default Javascript question

    I decided to give up trying to hunt down the perfect javascript menu and make one myself.

    Thing is, there's this part about loading a .js file directly onto the page instead of writing it straight on the page that I don't get. Supposedly, you're supposed to write "<script src="linky.js"></script>" is wherever you want the script to be, then create a separate file "linky.js", and whatever is in that .js file should appear wherever you intended it to be.

    Tested it on the page directly, works fine.

    Tried the loading separately technique, got zilch.

    So like, anyone can tell me what I'm doing wrong?
    Roarkiller
    The only one there is

    Roarkiller.net

    The Last TCG Moderator

  2. #2
    Cloyster Moderator
    Moderator
    Jeff's Avatar
    Join Date
    Nov 2004
    Location
    Maryland, USA
    Posts
    4,453

    Default Re: Javascript question

    I'd make sure the <script> tag is inside the head tags, and add type="text/javascript" to the script tag, and see if it works.
    Winner of the Unown Awards: 2008 "Hard Work", 2010 "Dedicated", 2012 "Journalist", 2012 "Unown", 2013 "Anchorman", 2014 "Unown", 2015 "Jeff Jeff Jeff Jeff!"



    Facebook - YouTube - Miiverse
    Diamond: 1418 3196 1413 - SoulSilver: 0217 4582 5426 - White: 1119 9535 7054 - White 2: 1421 4560 4887 - X: same as 3DS
    3DS: 3866 8018 5231 - AIM: IslanderJeff02
    Joined November 8, 2004 - Modded October 24, 2008

  3. #3
    Slugma Extraordinaire Junior Trainer
    Junior Trainer
    Negrek's Avatar
    Join Date
    May 2006
    Location
    Lurking
    Posts
    286

    Default Re: Javascript question

    Well, you have the correct code there, so I'd guess that there's just some silly little mistake somewhere that is screwing things up.

    First, make sure that you didn't put those script tags into the "head" area of the document by accident (unless the JavaScript is supposed to be placed there and not in the body of the document).

    Second, make sure that you spelled everything right, remembered to close your quotation marks on the link name, and stuff like that (I always screw that up, myself).

    Make sure that there are no <script> tags within the external file itself.

    If you're using relative linking like that (i.e. "filename.js" instead of "http://.....js"), make sure that you have everything in the same directory. Also make absolutely sure that you saved the script as a .js and not something else.

    Yeah. It should work the way you've done it, so if none of those things seems to be the problem, perhaps post the source and I can look and see if I can figure out what's wrong with it; with what you've said, though, I couldn't think of anything else that might be a problem.
    Avatar made by Jade Dragonair. Thanks very much, JD!

  4. #4
    Da Big Cheez of TCG Master Trainer
    Master Trainer
    Roarkiller's Avatar
    Join Date
    Jan 2001
    Location
    Singapore
    Posts
    7,588

    Default Re: Javascript question

    It's in the body, not the head.

    <script src="linky.js"></script>

    Here's what's inside the js file.

    document.write("testing")

    Simple basic write line. Still zilch. FYI for those wanting to know, I'm trying to do away with including a standard HTML menu on the side in every page, so I don't have to edit every page should I wnt to change the menu, so I figured javascript would be the safest bet (I'm not using frames, or iframes for that matter).
    Roarkiller
    The only one there is

    Roarkiller.net

    The Last TCG Moderator

  5. #5
    Cloyster Moderator
    Moderator
    Jeff's Avatar
    Join Date
    Nov 2004
    Location
    Maryland, USA
    Posts
    4,453

    Default Re: Javascript question

    That's weird, it should be working, I tried it myself several different ways, in the head, in the body, with and without the type attribute defined. It worked every time (yeah even when placed in the head even though document.write code is supposed to go in the body).

    What browser(s) are you testing this under?
    Winner of the Unown Awards: 2008 "Hard Work", 2010 "Dedicated", 2012 "Journalist", 2012 "Unown", 2013 "Anchorman", 2014 "Unown", 2015 "Jeff Jeff Jeff Jeff!"



    Facebook - YouTube - Miiverse
    Diamond: 1418 3196 1413 - SoulSilver: 0217 4582 5426 - White: 1119 9535 7054 - White 2: 1421 4560 4887 - X: same as 3DS
    3DS: 3866 8018 5231 - AIM: IslanderJeff02
    Joined November 8, 2004 - Modded October 24, 2008

  6. #6
    Da Big Cheez of TCG Master Trainer
    Master Trainer
    Roarkiller's Avatar
    Join Date
    Jan 2001
    Location
    Singapore
    Posts
    7,588

    Default Re: Javascript question

    Tried rewriting a test page, is working now. Still, I can't get a link out.

    <a href="javascripttart('index.html')";>index</a>
    <a href="index.html">index</a>

    That's what I changed, testing both a js link and a standard html link. Nothing came out.
    Roarkiller
    The only one there is

    Roarkiller.net

    The Last TCG Moderator

  7. #7
    Administrator
    Administrator

    Join Date
    Apr 2001
    Posts
    19,363

    Default Re: Javascript question

    Make sure your server is reporting the MIME type of the external Javascript file as "text/javascript" otherwise some browsers (Firefox springs to mind) will refuse to execute the code.
    n/t

  8. #8
    Slugma Extraordinaire Junior Trainer
    Junior Trainer
    Negrek's Avatar
    Join Date
    May 2006
    Location
    Lurking
    Posts
    286

    Default Re: Javascript question

    FYI for those wanting to know, I'm trying to do away with including a standard HTML menu on the side in every page, so I don't have to edit every page should I wnt to change the menu, so I figured javascript would be the safest bet (I'm not using frames, or iframes for that matter).
    If that's what you're doing with it, IMO you should use SSI instead. Very simple to use, obviously doesn't have problems with people who disable JavaScript or whatever, and it's designed especially to do stuff like include navigation bars where you only want to modify one file to have the changes appear on every page in a web site. Also doesn't suffer the same problems as frames/iframes. JavaScript isn't really designed to insert content like that.
    Last edited by Negrek; 15th June 2007 at 11:09 AM. Reason: WTF was I calling it shtml for?
    Avatar made by Jade Dragonair. Thanks very much, JD!

  9. #9
    Administrator
    Administrator

    Join Date
    Apr 2001
    Posts
    19,363

    Default Re: Javascript question

    Quote Originally Posted by Negrek View Post
    If that's what you're doing with it, IMO you should use shtml instead. Very simple to use, obviously doesn't have problems with people who disable JavaScript or whatever, and it's designed especially to do stuff like include navigation bars where you only want to modify one file to have the changes appear on every page in a web site. Also doesn't suffer the same problems as frames/iframes. JavaScript isn't really designed to insert content like that.
    This is a pretty good solution and you should use this if your web server supports it. Most shared hosts still do.
    n/t

  10. #10
    Da Big Cheez of TCG Master Trainer
    Master Trainer
    Roarkiller's Avatar
    Join Date
    Jan 2001
    Location
    Singapore
    Posts
    7,588

    Default Re: Javascript question

    Geocities doesn't. Hence javascript.

    If you're wondering, SSI was what I have been using for all my non geocities-based webpages.

    Make sure your server is reporting the MIME type of the external Javascript file as "text/javascript" otherwise some browsers (Firefox springs to mind) will refuse to execute the code.
    Not very sure what you're talking about here. And uh, firefoz ain't gonna support this? Huh?

    Btw, regarding my last post, that looks right, doesn't it?
    Roarkiller
    The only one there is

    Roarkiller.net

    The Last TCG Moderator

  11. #11
    Slugma Extraordinaire Junior Trainer
    Junior Trainer
    Negrek's Avatar
    Join Date
    May 2006
    Location
    Lurking
    Posts
    286

    Default Re: Javascript question

    IMO you should seek better free hosting than Geocities, but eh.

    Firefox will support external JavaScript, but you have to make sure that the file is being correctly reported as a text/JavaScript file. If it's not, then you could try adding

    <link href="whatever.js" type="text/javascript">

    to the <head> of the page; I have no idea if that would clear the problem up or not, but I suppose it's worth a shot.
    Avatar made by Jade Dragonair. Thanks very much, JD!

Posting Permissions

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