chess19 Posted September 11, 2008 Share Posted September 11, 2008 I've been working on a project in my free time in school (I've got several computer classes), it's fairly small and simple, it simply shows a specific file (Theoretically a .txt file) in a iframe, and refreshes the file periodically. (Every 5-10 seconds)Some of my friends and I have been using this script as a stand-in Instant Messenger to communicate in class. It works fine, too. (Technically, none of this is against the rules. Just a bit of a loophole)The problem is that I'd like to be able to check the content of the txt file. If the content has changed, I would like the window to be focused. The problem is that I can't seem to get at the actual text of the file. Since we obviously aren't including <html> tags at the top and bottom of our messages, I can't access it using the HTML DOM stuff I know. Is there any easy way to access the text of a .txt file when it is loaded into a frame?I would include my current code, but I do not have it on this computer, and little of it is particularly relevant to the question.The .txt file is loaded into the iframe by using iframe.location = form.textarea.value (Obviously I don't actually use the words form iframe or textarea, I'm just substituting). It is refreshed by recalling that line. I know there are functions for setting locations, but I had trouble with them. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 12, 2008 Share Posted September 12, 2008 Javascript can read any file in the same domain if you use AJAX to access the file. Send out an AJAX request for the file and the response that comes back will be the contents of the file. You can probably use that method to update the iframe (or use a div instead of an iframe) also. This thread has some AJAX utility functions and a description about how to use them:http://w3schools.invisionzone.com/index.php?showtopic=5 Link to comment Share on other sites More sharing options...
chess19 Posted September 12, 2008 Author Share Posted September 12, 2008 Thanks, I'll look into it. Link to comment Share on other sites More sharing options...
chess19 Posted September 16, 2008 Author Share Posted September 16, 2008 Gah, foiled. Got an access denied message. I think the server doesn't allow those sort of requests. Link to comment Share on other sites More sharing options...
jeffman Posted September 16, 2008 Share Posted September 16, 2008 First, try sending the HTTP request as a GET, not a POST. If it still doesn't work, show us the AJAX code you put together. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 16, 2008 Share Posted September 16, 2008 AJAX also can't be used across different domains, an AJAX request can only go to the same server where the HTML page is located. If you need to send an AJAX request to a remote file you'll need to create a PHP page that can act as a proxy, so you send an AJAX request to your local PHP proxy telling it what file you want, and that page sends out a request to the remote file (PHP can do that), and then sends the data back to your Javascript code. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.