Results 1 to 5 of 5

Thread: Help Required with Bookmark Site Script

  1. #1
    Join Date
    Nov 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help Required with Bookmark Site Script

    Hi,

    I am quite new to Javascript and I usually copy and paste.

    I have seen your excellent Bookmark Site Script which works in Firefox & IE
    and I would like to know if it is possible to save the "Head" part of the script in an external .js file?

    If it is possible to do this, what code change is required for the javascipt command in the Body Section?

    Many thanks

    Jeremy I

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,475
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    If done correctly, the part in the body remains unchanged, here are my general guidelines for making a script external:


    Use a text editor to save the script, call it 'file_name.js' where 'file_name' can be any valid file name of your choosing. Substitute the name of your external .js file for some.js in the below:

    HTML Code:
    <script src="some.js" type="text/javascript"></script>
    Common problems arise when:

    1 ) The script file is not in the directory specified. In this example it must be in the same directory as the page(s) that use it.

    2 ) Opening, closing and/or 'hiding' tags are left in the external file. This means that you must strip:
    Code:
    <script>
    <!--
    and
    Code:
    //-->
    </script>
    and any of their many variations from the beginning and end of the external file.

    3 ) The external call (<script src="some.js" type="text/javascript"></script>) is not inserted into the page at the correct spot. The external call must be inserted at the same place on the page where the script was/would have been.

    4 ) Paths to other files (if) used by the script are no longer valid due to its location. This is only a problem if the external script is kept in a different directory than the page it was working on when it was an internal script. To correct this, use absolute paths inside the script.

    5 ) Inappropriately combining two or more scripts into one external file. Usually external scripts can be combined if one knows enough about scripting to do so properly. Even then it is possible to overlook something.

    A rule of thumb when testing is, if it won't work on the page, it won't work as an external file either.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Nov 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem with External Scripts

    Hi John,

    Thanks for the advice. In the past I have created external scripts and saved them correctly in other locations. I have complied mostly with your suggestions.

    I can get the script to work by making the Script Internal.

    I have an external Javascript folder in the site and I think that the only problem that I have is to try and redirect the link below to the folder.

    <a href="javascript:bookmarksite('Dynamic Drive', 'http://www.dynamicdrive.com')">Bookmark this site!</a>

    I have tried re-writing: <a href="javascript:bookmarksite( but I canīt seem to get it to work.

    Any suggestions appreciated.

    Best regards

    Jeremy I

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,475
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That part (in the body) doesn't need to be directed to any folder (it does need to be edited to reference the page you want bookmarked instead of Dynamic Drive). A call to the external script, placed in the head (where the script was when internal) does need to include the path to the external script, if different than the page's path:

    Code:
    <script src="script/some.js" type="text/javascript"></script>
    or

    Code:
    <script src="../script/some.js" type="text/javascript"></script>
    or whatever is the correct path on the server there.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Nov 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Many Thanks

    Thanks John,

    It works perfectly.

    I appreciate your help,

    Best regards,

    Jeremy I

Bookmarks

Posting Permissions

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