Forum Moderators: open

Message Too Old, No Replies

Javascript Code Execution with eval()

loading text file to execute as js code.

         

Quasaur1

5:48 am on Nov 9, 2004 (gmt 0)

10+ Year Member



in a js file i want to load a text file with javascript code in it.

then i want to execute the code.

any ideas?

adni18

1:29 pm on Nov 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<script language=javascript type="text/javascript" src="text.txt"></script>

Or...You might want to do some kind of PHP or Perl scripting... Maybe something like this:

page.html:


<script language=javascript type="text/javascript">
<!--#include virtual="script.cgi"-->
</script>

script.cgi:


#!/usr/bin/perl
print "Content-type:text/html\n\n";
open(INPUT,"text.txt");
while(<INPUT>)
{
print;
}

Quasaur1

3:52 am on Nov 10, 2004 (gmt 0)

10+ Year Member



i dont have access to the server...everything needs to be done in javascript.

adni18

11:57 am on Nov 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



then try the first choice.

Quasaur1

10:05 pm on Nov 10, 2004 (gmt 0)

10+ Year Member



Thanks for the feedback; please allow me to elaborate:

I'm building on my web site an online Bible as a project to learn XML:

(http://www.clmitchell.net/Bible/index.html).

The goals of the project are:

1)To use a single, dynamically-updated (js) web page (XHTML) to present all the books of the Bible, one chapter at a time.

2)To render the actual text of each chapter from an XML file existing on the web dir on the server (i.e., Genesis is a single XML file with 50 chapters).

3)To Use javascript to update the web page depending on the choice of the user (i.e., i dont want to have a single, HUGE js file with all possible pages in it; but would rather CALL other javascript files from a single MAIN js file [i've already achieved some success so far].

what is working NOW is:

1)user presses a button on main web page.

2)button calls MAIN js file/function requesting a particular "page" rendering.

3)using a switch/case block, the appropriate js file is called by dynamically adding a <script> tag to the <head> tag that calls the requested script that will render the proper page.

4)div that contains the PRIMARY CONTENT (i.e. menus & chapters available) is cleared and updated [THIS IS WHERE THE PROBLEM IS!].

5) button behaviors are changed to match the options available for the new page.

what is NOT WORKING is that the background-image (declared in a linked stylesheet) for the div i am updating wont be updated (i send a command that replaces the default bg-image with a transparent gif:)

************************
//remove background image
if(IE6)document.all['DataTab'].style.backgroundImage = 'url(images/blank.gif) no-repeat';
if (NS6)document.getElementById('DataTab').style.background = 'url(images/blank.gif) no-repeat';

************************
i've tried EVERY COMBINATION of single- and double-quotes to get this code to replace the image without success...WHERE HAVE I ERRED?

adni18

12:14 am on Nov 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you have more than one DIV tag by that ID, that could be a problem. There is also another problem. Try this instead of calling the objects:


if(navigator.appName.indexOf("Internet Explorer")!=-1)
{
document.all.DataTab.style.backgroundImage = 'url(images/blank.gif) no-repeat';
}
else if (navigator.appName.indexOf("Netscape")!=-1)
{
document.getElementById('DataTab').style.background = 'url(images/blank.gif) no-repeat';
}

Quasaur1

12:41 am on Nov 11, 2004 (gmt 0)

10+ Year Member



Thanks for taking the time to respond...

however, while the NS6 Javascript Console gives no error the default background image doesn't go away, either.

I'm assuming that the new image REPLACES the old one...but is it just "siting on top of" the original image (blank.gif is a single-pixel transparency)?

adni18

12:52 am on Nov 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes. But if it's just one pixel, I don't think anyone will notice. I noticed that Netscape didn't like it also. You might just want to set the background to "".

Quasaur1

12:59 am on Nov 11, 2004 (gmt 0)

10+ Year Member



your logic (using a null string to eliminate the background) is indomitable...

...however, that doesn't seem to work, either...

but something did occur to me: can't i render the background in-visible (without changing the visibility of the containing div)?

adni18

1:06 am on Nov 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you could try .style.background="transparent". But that usually only works in IE. I think you should render it as a solid color.

krishnarao

6:44 am on Nov 11, 2004 (gmt 0)

10+ Year Member



Hi,
The reason could be the object you are referring may not be available when you are updating the page content. So, you can update the background using embedded stylesheet. For example, you can get the javascript to print the following:

<div background="image.jpg">
content

</div>

Let me know if this solves the problem.

Cheers,
Krishna.

Quasaur1

4:36 pm on Nov 11, 2004 (gmt 0)

10+ Year Member



THANKS EVERYONE FOR YOUR INPUT...

But i've now given the div a new class that leaves out the bg-image, so i'm going to CLOSE THIS DICUSSION.