#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    2
    Rep Power
    0

    Question Javascript include file (different)


    How do you include a file (not .js) in a javascript text?
    I have a javascript text all laid out but I wanted to include another file a .txt file into it so it'll load of the .txt file and display the javascript with the .txt file inside of it. How can I do that?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Posts
    1,882
    Rep Power
    19
    Something like this?

    Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    
    <script>
    function blah()
    {
    document.write('<script src="file.txt"><\/script>');
    }
    </script>
    
    </head>
    
    <body>
    
    <script>
    blah();
    </script>
    </body>
    </html>
    document.write('<script src="file.txt"><\/script>');

    Notice that you have to escape some characters with a blackslash, such as forward slashes.


    You could use it in something like this
    Code:
    var isIE = navigator.userAgent.indexOf("MSIE") != -1 && !isOpera 
    
    function menuTable() //Import the Menu from ie_menu.js or non_ie_menu.js
    {
    if (isIE) //Check for IE
           { //document.write the script into the code
            document.write('<script type="text\/javascript" language="JavaScript" src="ie_menu.js"><\/script>');
             }
           else
            { // So you should be using Nav 4 or Opera!
    		document.write('<script type="text\/javascript" language="JavaScript" src="non_ie_menu.js"><\/script>');
    
        }
    }
  4. #3
  5. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    I have a javascript text all laid out but I wanted to include another file a .txt file into it so it'll load of the .txt file
    and display the javascript with the .txt file inside of it. How can I do that?
    This is not clear. JS files are text files, you can't 'include' other files within them, and JS files aren't displayed -
    they're run, since JS is a programming (scripting) language. What was it you needed to accomplish? Probably pretty simple...
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    2
    Rep Power
    0
    ok not really. I don't want to include a .js file. Iknow that javascript is text but... ok here... this is the code I'm using:
    This code won't work I don't think if you try and use it. I am not too sure about javascript...
    Code:
    <applet code="OCVscroll" codebase="." align="baseline" height="20" width="600">
    
    
    
    <!--General / Default Settings-->
    <param name="bgcolor" value="#0000CC">
    <param name="textcolor" value="#00CCCC">
    <param name="font" value="Helvetica, plain, 12">
    <param name="halign" value="Left">
    <param name="lrmargin" value="5">
    <param name="hlcolor" value="#ffffff">
    <param name="delay" value="50">
    <param name="scrolldelay" value="50">
    <param name="loadwhere" value="mainFrame">
    
    <!--Specific Settings-->
    <param name="desc0" value="I want to put the other file here ">
    <param name="loadwhere0" value="mainFrame">
    </applet>
    That's the javascript text. I want to use another file to put in the scroller where it says I want to put the other file here that way when the scroller loads it'll load from the text file not .js and use that to display the news I want. if you see: here is what I want to use it for down at the bottom is a scroller that loads and hopefully works. I want to put text there from a .txt file. Can you include a file in javascript like that? take the javascript code and include another .txt file inside of it? if not is there any way I can get around this?

IMN logo majestic logo threadwatch logo seochat tools logo