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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can I "include" a page with JS on another html page?

    I am using FrontPage. I have created a html page with a JavaScript mouseover menu, and I would like to use "include" to incorporate this menu into all my other web site pages, without have to put the JS declarations into each individual page (which kind of defeats the purpose of the include). The "include" only brings in the "body" piece of the JS, but not the code that is needed in the "head".

    Is there a way I can do this? Can I use a style sheet? I am not very experienced with style sheets. What kind of syntex would I use?

  • #2
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    You can use a javascript include:

    Just put the script into another file without script tags and give it a .js extention. Then reference it like this:

    <script type="text/javascript" src="yourpage.js"></script>

    and place it where you would normally place the whole code.

    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #3
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JS include worked great, but I have one more question

    Thanks! The instructions you sent worked great.

    One more related question tho:
    On the same html page where I am using this first js include I asked you about, there is also another JS script that I would like to add. I assume I can add a second reference with a second JS include with the other file name on my html page.

    But this is my problem.
    The second JS script (for a dropdown menu) starts out with a CSS style type before the JS script tags actually start.

    <style type="text/css">
    #dropmenudiv{
    position:absolute;
    border:1px solid black;
    border-bottom-width: 0;
    font:normal 12px Times New Roman;
    line-height:18px;
    z-index:100;
    }

    #dropmenudiv a{
    width: 100%;
    display: block;
    text-indent: 3px;
    border-bottom: 1px solid black;
    padding: 1px 0;
    text-decoration: none;
    font-weight: bold;

    }

    #dropmenudiv a:hover{ /*hover background color*/
    background-color:red;

    }

    </style>


    Then the JS begins:
    <script type="text/javascript">


    //Contents for menu 1
    var menu1=new Array()
    menu1[0]='<a href="http://www.scout_team.com">Uniform Order Form</a>'
    menu1[1]='<a href="http://www.scout_team.com">Letter of Acceptance</a>'
    menu1[2]='<a href="http://scout_tema.com">New Player Tryouts/Registration Form</a>'
    menu1[3]='<a href="http://scout_team.com">CSS Drive</a>'


    etc.

    I have created separate .js & .css files (both without the script tags).
    First I tried calling both the .js and the.css files from my html page, which didn't work.

    Then I then tried calling the .css file from the .js file, and calling only the .js file from the html page. That didn't work either. Altho I don't know whether my syntax for calling the files was correct.

    When I tried calling the both the .js & .css files from my html page I tried using either:
    <link rel="stylesheet" type="text/css" href=dropdowntest.css">
    <script type="text/javascript" src="dropdown.js"></script>

    or
    <script type="text/css" src="dropdowntest.css"></script>
    <script type="text/javascript" src="dropdown.js"></script>

    I got a syntax errors with both.

    Then I tried calling only the .js from my html page, and calling the .css file from the .js file:
    In the html page I used:
    <script type="text/javascript" src="dropdown.js"></script>

    In the .js file I used:
    <link rel="stylesheet" type="text/css" href="dropdowntest.css">

    I also tried using, in the .js file:
    <script type="text/css" src="dropdowntest.css"></script>

    For both I got menu undefined.

    Is there a way I can do this?


  •  

    Posting Permissions

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