41 users online (0 members and 41 guests)  

Thread: Site searches


  Results 1 to 5 of 5
  1. #1
    nassau12's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Nov 2002
    Location
    Princeton, NJ
    Posts
    32

    Calling contents of an external js file

    Ok! Be gentle on this newbie. How do I set up an external js file?

    Then, how do I call for the contents of this file to appear embedded at a specific location in a html file?
    Last edited by nassau12; 05-13-2003 at 03:15 PM.

  2. #2
    Saj's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Feb 2003
    Posts
    35
    Well if you know JavaScript, you know the proper layout. You have the code between the <script> tags. All you have to do is take that code without the <script> tags and just dump it into a js file. You can make one in notepad. When you save, just select "All files" rather than "Text .txt" and your set.

    You call it to the HTML page by adding this:

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

    To call functions, you just do the same thing as you would if the javascript were inside the html page:

    <a href="javascript:void(0)" onclick="javascript:yourfunction()">Click here to start the function!</a>

  3. #3
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652
    Place the name of the .js file to be included inside the </HEAD> tag of the HTML file which calls the function. Most of my functions are encoded within my HTML files like this:

    <SCRIPT language="JavaScript">searchgo('HTML help')</SCRIPT>


    That's a call to the function that displays the 'www' and 'site' check-off style Google search box with image and includes the search phrase "HTML help" inside the search box. The function inside my master search.js file is (note that the right side code is truncated, so this won't work without some editing):
    Code:
    /*  <SCRIPT language="JavaScript">searchgo('(g)','not')</SCRIPT>
      GoogleFORMupdated 7/17/02 */
    function searchgo(phrase,v1) {
    var win = "_new"
    var fill = "</NOBR></TH></TR></TABLE></FORM>"
    if (phrase == "(g)") { dum=phrase;phrase="";win="credit" } else { dum="" }
    if (phrase=="") { j = 20 } else { j = phrase.length }
    if (v1=="not") { f1 = "" } else { f1 = "<BR>" }
    document.write("<FORM ACTION=http://www.google.com/custom method=GET TARGET="
    + win + "><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><TH NOWRAP>" + dum
    + "<A HREF='http://news.google.com/' TARGET=" + win + "><IMG ALT=GoogleReport
    + " BORDER=0 WIDTH=91 HEIGHT=35 SRC=" + path + "i/!google.gif></A>"
    + "</TH><TH><NOBR><INPUT TYPE=text name=q size=" + j + " maxlength=255 value=
    + phrase + "'>" + f1 + "<INPUT type=submit name=sa VALUE='Search'>"
    + "<INPUT type=hidden name=cof VALUE='LW:115;L:http://......"
    + "<INPUT type=hidden name=domains value='jamrent.50megs.com'>");
    if (v1=="not") { document.write(fill); } else {
    document.write("<B ID=mendu0>"
    + "<input type=radio name=sitesearch value='' checked>www"
    + "<input type=radio name=sitesearch value='jamrent.50megs.com'>site"
    + "</B>" + fill);
    }
    }
    Last edited by HTML; 03-20-2007 at 08:37 PM.

  4. #4
    nassau12's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Nov 2002
    Location
    Princeton, NJ
    Posts
    32
    Thanks for the help. I knew that you would have the answer.
    You would be surprised how difficult it is to find this kind of information in standard tech manuals and tutorials.

  5. #5
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652
    Yeah, forums like this didn't exist when I learned basic HTML the hard way - mostly by looking at the source code of others to see how they did it.



Tags for this Thread