Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

So, I'm not sure if the reason I'm having trouble with this is because it looks awfully like malicious activity or not. What I'm attempting to do is make my life a little less terrible with a piece of very inflexible and outdated web-based software.

Basically, there's a block of HTML that I can edit from within the software (it's inserted into a td element), and I want to have the content of that block come from a plaintext file on my local drive, being synced to the cloud with Dropbox.

It is possible to do something like this:

<td>
  <script>
    insert_text_from_url("https://dl.dropboxusercontent.com/s/blahblahblah/file.txt?token_hash=blahblahblah&dl=1");
  </script>
</td>

With the output being <td>[contentsof_file.txt]</td>?

share|improve this question
    
Would <iframe> work? You can do what you want with javascript, but it's not a simple, single function. –  Darth Android Aug 26 '13 at 16:06
    
I was hoping not to use an iframe since it's much less elegant, but I'm somehow not able to get that to work either. –  NReilingh Aug 26 '13 at 16:09
    
XSS is prevented by most browser JavaScript implementations. –  Synetech Dec 31 '13 at 5:53
    
@Synetech Yes, this was my issue in testing, since the browser realized it was loading the same code being submitted in the previous page load. But, all the browsers I've tested have been okay loading a .js file from a remote server as long as everything is under SSL. –  NReilingh Dec 31 '13 at 5:55

2 Answers 2

You can accomplish this with JQuery. You'll want to have a way you can lookup your td, like giving it an id:

<td id="insertTextHere">
</td>
<script>
    $(function(){
          $('#insertTextHere').load('https://dl.dropboxusercontent.com/s/blahblahblah/file.txt?token_hash=blahblahblah&dl=1');
    });
</script>
share|improve this answer
up vote 0 down vote accepted

Rather than load a remote plaintext file, it turned out to be much easier to make the remote file a JavaScript "wrapper" that had the plaintext inlined using a rather-hackish "multiline text variable":

remote_editable_file.js:

var myString = function(){/*

Editable plaintext or whatever goes here!
Multiline, too!

*/}.toString().slice(15,-4);
document.getElementById('content').innerHTML = myString;

The last line is what does all the work; it's simple enough that jQuery is overkill unless you run into insurmountable portability issues.

In the originating page (the block of HTML that is only editable manually), all you then need is:

<div id="content"></div>
<script src="https://dropbox/link/to/remote_editable_file.js" type="text/javascript"></script>
share|improve this answer
    
The last line does nothing more than to assign the contents of the specified element. Your answer is confusing because you said you wanted the contents of the file to be inserted, but nowhere in it have you specified a URL. Where are the contents of the file coming from? ಠ_ఠ Unless I’ve suddenly lost all knowledge of computers, I don’t see how your answer could possibly accomplish what you had asked. –  Synetech Dec 31 '13 at 5:57
    
@Synetech Clarified. –  NReilingh Dec 31 '13 at 6:00
    
…it was loading the same code being submitted in the previous page load… In the originating page… Actually it’s more confusing now. What/where is this other page? I still don’t see where the .txt file or its contents come in. –  Synetech Dec 31 '13 at 6:03
    
@Synetech Sorry; edited again. Give it one more try? –  NReilingh Dec 31 '13 at 6:11
    
So in other words, you gave up trying to load an external file and just put it directly in the .js file? In that case, why bother with a separate file? Why not just put it directly in the .html file? Is it something that would be used in multiple files? –  Synetech Dec 31 '13 at 6:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.