Jump to content

Document.write & Document.createelement To Display External Website Html.


paulmo

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...