-1

I'm creating a really simple personal userscript. What I want it to do is to import a html code from somewhere else (ie. a file from my public dropbox folder).

I was thinking something in the lines of this:

var element = document.getElementById("notes");
var widget = ??? //import HTML form publicly accesible file
element.innerHTML = widget

Is it possible? Preferably in pure vanilla JS.

JonnyRobbie
  • 526
  • 5
  • 16
  • you can use YQL to grab html from some sites and turn it into jsonp that a script on your page can template into your document. – dandavis Oct 09 '13 at 20:06

1 Answers1

0

Your question resumes to this, how to make an ajax http request in pure javascript.

How to get the response of XMLHttpRequest?

But I really suggest you use jquery or any other lightweight javascript to do it. Both for syntax that is easier, and for browser compatibility with IE mostrly.

With jquery you could do:

var element = document.getElementById("notes");
$.get('dropbox url').done(function(data){
   element.innerHTML = data;
});

I hope this helps.

UPDATE 1: I'm sorry, I forgot about cross domain policy. It probably won't work the way I described. For you case mayber the best way is to add an iframe where you want your page to load this.

Community
  • 1
  • 1
digao_mb
  • 1,294
  • 16
  • 23