Closed Thread Icon

Topic awaiting preservation: Calling an external file in a script (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=24615" title="Pages that link to Topic awaiting preservation: Calling an external file in a script (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Calling an external file in a script <span class="small">(Page 1 of 1)</span>\

 
Suho1004
Maniac (V) Mad Librarian

From: Seoul, Korea
Insane since: Apr 2002

posted posted 01-07-2005 15:52

OK, I'm pretty sure I once knew how to do this, years back, but my JS knowledge has gone from minimal to virtually non-existent in the intervening years. But enough of the excuses. What I want to do is have a script pop-up a window that will contain text drawn from a file. I'm probably trying to do this the wrong way, since I'm trying to figure out how to do this with document.write(). I guess what I'm looking for is the JS equivalent of the PHP include(). Or is it not done this way in JS?

Sorry for the stupid question, but I am a JS idiot. Thanks in advance for any help.

___________________________
Suho: www.liminality.org | Cell 270 | Sig Rotator | the Fellowship of Sup | "Hooray for linguistic idiots and yak milk!"

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 01-07-2005 16:21

First of all, what does your text file contain and what's its format ? are you sure you can't open a simple popup with a parameter in the URL for a PHP to load the appropriate file ?

Otherwise if you must use JS, you have 2 options :

1. the oldschool method : remote scripting. You'll need to format your text files in JS and put the blah blah in some variable. To dynamically load these files you could either use a document.write( ) to create a new line with <script type="text/javasript" src="myTextFile.js" ></script>, or you can use the DOM to create a similar SCRIPT object and append it in the HEAD.

2. the newschool method: XmlHTTPRequest. Read the page entitled Dynamic HTML and XML: The XMLHttpRequest Object to get a quick overview of the XMLHTTPRequest object its methods and properties. Once you've loaded your external file you can retrieve its content as a string via the responseText property.

Hope that helps,

Suho1004
Maniac (V) Mad Librarian

From: Seoul, Korea
Insane since: Apr 2002

posted posted 01-08-2005 03:20

Thanks for the reply, poi. To answer your questions, the file is just a simple piece of text, formatted as html. In fact, you can see the text in question on my website: it's the text that's in the box at the top of the page, titled "the latest at Liminality." I want to get rid of that box (which tends to take up a lot of vertical space, depending on how much text there is) and replace it with a simple link to a pop-up. I've got the pop-up working, now I just need to get the text into the window.

The first option sounds like it would be something of a pain in the neck (having to format the text in JS), while the second one is a bit over my head. To be honest, the "open a simple popup with a parameter in the URL for a PHP to load the appropriate file" route seems like the best bet, especially since it's always the same file and I wouldn't need to pass a parameter. I don't know why I didn't think of that before. I should get the chance to fiddle later on today, and if I can get it all figgered out I'll post the results.

___________________________
Suho: www.liminality.org | Cell 270 | Sig Rotator | the Fellowship of Sup | "Hooray for linguistic idiots and yak milk!"

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 01-08-2005 09:48

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 01-08-2005 11:15

you're welcome.
you wanted to create a script for a single file formatted as HTML

Suho1004
Maniac (V) Mad Librarian

From: Seoul, Korea
Insane since: Apr 2002

posted posted 01-08-2005 12:20

OK, apparently I am an idiot, because I can't seem to get this working. I'm sure it's very simple, but I can't seem to wrap my head around it.

I think part of the problem is the way my site is set up. I have htaccess set up to send all queries to a php page that parses the query url and then serves up the proper content. The only exceptions to this are graphics, css, and javscript. I cannot make an exception for html because a lot of the content is stored in static html pages. I can't just make a regular pop-up that links to an html page, in other words, because it gets directed to my php script which tries to parse it. I suppose I could rework my php script to include that content, but I'd prefer a simpler "inclusion" solution.

Am I making any sense? I'm not even sure I understand me.

I tried to throw a php include into my javascript pop-up function, which uses document.write() to build the page that appears in the pop-up (this is the function that Bugs uses for his pop-up photos, which I modified for my site and then modified again for this task). It's not working because the browser doesn't recognize it as a php file. How do I get the browser to recognize it as a PHP file? Or should I do this another way? Or should I just go back to beating my head against the wall.

In replying, please understand that I am currently suffering from an extreme (possibly fatal) case of stupidity. Use small words if at all possible. Much thanks, apologies for stupidity, you know the drill.

___________________________
Suho: www.liminality.org | Cell 270 | Sig Rotator | the Fellowship of Sup | "Hooray for linguistic idiots and yak milk!"

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 01-08-2005 12:34

[quick_reply_and_hack] if your .htaccess route the .html files to you PHP content parser, couldn't you do an exception for the .htm ( with no "l" at the end ) files ? [/quick_reply_and_hack]

Suho1004
Maniac (V) Mad Librarian

From: Seoul, Korea
Insane since: Apr 2002

posted posted 01-08-2005 13:43

Hmm... now there's an idea I hadn't thought of. That would probably work.

[Edit: Worked like a charm. Brilliant.

So simple, yet so effective. Now if only I can figure out how to come up with these things myself...]

___________________________
Suho: www.liminality.org | Cell 270 | Sig Rotator | the Fellowship of Sup | "Hooray for linguistic idiots and yak milk!"

(Edited by Suho1004 on 01-08-2005 14:03)

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 01-08-2005 14:23

glad it works now.
The basic idea to approach a problem is to KISS it. Keep It Simple Stupid. If a solution seems too complex, it certainly is and there's all the chances you didn't paid enough attention to a detail that would help simplifying it.

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 01-08-2005 14:42

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Suho1004
Maniac (V) Mad Librarian

From: Seoul, Korea
Insane since: Apr 2002

posted posted 01-08-2005 15:09

InI: Well, I can see why you might say that, but I made that choice on purpose, and aside from this minor (well, what turned out to be minor) glitch it has worked for me.

Although, it actually wouldn't be a big deal to make html usable again--all I would have to do is set it up that way in my .htaccess file. I excluded html in the beginning because I wasn't sure if people were going to try to get to the content by accessing the html files rather than by going through the virtual directory structure I had set up. It wouldn't be that hard to change how I have things set up, though, if I really needed to allow people to directly access html (for example, I just give my content files a different extension and make an exception for html in .htaccess), I just haven't seen the need so far (aside from this little fiasco).

I am curious as to what this potential bottleneck is that you speak of. What did you have in mind? I really can't think of any bottlenecks, but perhaps you have a different perspective.

___________________________
Suho: www.liminality.org | Cell 270 | Sig Rotator | the Fellowship of Sup | "Hooray for linguistic idiots and yak milk!"

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 01-09-2005 02:01

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Suho1004
Maniac (V) Mad Librarian

From: Seoul, Korea
Insane since: Apr 2002

posted posted 01-09-2005 03:53

Thanks, InI. I appreciate the concern and your perspective. I did try my best to avoid the most common pitfalls when I first wrote the code (which, I must admit, was quite some time ago), such as "validating" the queries passed through the script. I tried to be as safety-minded as possible, but my knowledge in that field is limited. For instance, I would not know how to force mod rewrite to tell the php script to include a url from a remote domain. You say that in my case the risk is minor, which is somewhat comforting.

Just out of curiosity, though, how would you avoid this particular gap? If it were you, how would you go about it? I do not plan to do a rewrite of the code quite yet, but sometime this year I envision moving over to a database, and at that point I will most likely rewrite the code. I've learned a lot since I first put this site together, and anything else I can learn in the meantime would be helpful.

I understand the gist of your points, and they seem very logical to me, I just don't have as much experience in the area so it's difficult for me to understand it in concrete terms. For example, the idea that more entry points means more vulnerability makes sense to me on an abstract level, but on a concrete level I am unsure how to apply that knowledge.

Hadn't thought about the images directory being open... oversight on my part there... index file now in place.

Thanks again for the info and advice, well beyond the call of duty.

___________________________
Suho: www.liminality.org | Cell 270 | Sig Rotator | the Fellowship of Sup | "Hooray for linguistic idiots and yak milk!"

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 01-09-2005 11:04

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Suho1004
Maniac (V) Mad Librarian

From: Seoul, Korea
Insane since: Apr 2002

posted posted 01-09-2005 11:43

Thanks for taking the time to explain that. I did hear (or read, actually_ horror stories similar to what you are describing and did my best to avoid that in my code. To be perfectly honest, the code is not the neatest, but I tried to make sure that no malicious queries could get through. Because of the nature of my content, it wasn't as easy as a predefined array of all files on the site, but the idea is the same. Although after having this discussion, I realize that I can accomplish the same things in a much more efficient manner. I haven't really taken the time to think about the code much, but this thread has caused me to do that again.

I do appreciate the advice and suggestions. Let's just hope that I don't have to contend with too many prepubescent morons. Oh, and I'm glad you liked the site.

I almost forgot: I have since accomplished what I originally set out to do here, but I haven't had a chance to upload the changes yet. I intend to do that tonight (maybe in about two hours or so). Not that it's anything special, of course (it's actually quite rudimentary), but I figured I should at least post results, right?

[Edit: Well, the changes are online, but my site is coming up 404 for me... I can ftp to it, but it's dead in the water. I hope one of those prepubescent morons didn't get to it... ]

___________________________
Suho: www.liminality.org | Cell 270 | Sig Rotator | the Fellowship of Sup | "Hooray for linguistic idiots and yak milk!"

(Edited by Suho1004 on 01-09-2005 13:28)

« BackwardsOnwards »

Show Forum Drop Down Menu