paulmo Posted December 21, 2011 Share Posted December 21, 2011 scientist & co.: since my journey into using JSON and Javascript to retrieve external website data is going nowhere (I understand the cross browser problem defined by scientist and here but is this tutorial only for getting external .js files or html data from a website? I'd think it would do both, but I can't get it to work with the latter...), I am taking a step back, and trying to get external website html on my page as described here. I'm getting empty screens with nothing interesting in Firebug except the url of the site. Thanks in advance for some help or direction with either of these methods. My goal is to get external website text and binary data on my page without using php or javascript libraries, api's, etc. 1) document.write: var url = 'http://www.petsads.com/dog/herding_group/'; document.write('<script src="'+url+'"></scr'+'ipt>'); 2) DOM method: var script = document.createElement('script')script.src = 'http://www.petsads.com/dog/herding_group/'+Math.random() // now append the script into HEAD, it will fetched and executed (not sure how to implement...put this line in HEAD and previous in body?? v vdocument.documentElement.firstChild.appendChild(script) Link to comment Share on other sites More sharing options...
thescientist Posted December 21, 2011 Share Posted December 21, 2011 a script tag is meant to load javascript onto a page, and that is what your example is demonstrating. http://javascript.info/tutorial/document-write It's not going to do the same thing with a webpage just because you put a domain url in the src instead. Have you considered using an iframe instead? Link to comment Share on other sites More sharing options...
paulmo Posted December 21, 2011 Author Share Posted December 21, 2011 thanks for replying...thought I read that the methods would retrieve html as well...what purpose would just retrieving javascript have? guess I could look into iframes...have used those before doing ads on websites. Link to comment Share on other sites More sharing options...
thescientist Posted December 21, 2011 Share Posted December 21, 2011 what purpose would just retrieving javascript have?Google Analytics/+, and Facebook Like/JSDK come to mind guess I could look into iframes...have used those before doing ads on websites.I would still advocate the use a server side proxy, to be honest. Link to comment Share on other sites More sharing options...
paulmo Posted December 21, 2011 Author Share Posted December 21, 2011 ok thanks...that abandons my idea of thinking javascript might be useful for cross browser data exchanges. Link to comment Share on other sites More sharing options...
justsomeguy Posted December 21, 2011 Share Posted December 21, 2011 Javascript can be used for cross-domain data exchanges, but the data is in Javascript. That is what JSONP is used for. The remote server needs to explicitly support JSONP, you can't use Javascript to grab just any arbitrary data from any server. Proxies are used for that. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.