Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Possible to grab the "contents" of a page?

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
Hi,

Is there a way to grab the contents of a page, via Javascript?

Basically, we are gonna be having a very basic page (about 30 lines of HTML, with their listing stats) ... and we wanna offer a way to let them show this on their site.

I've thought about IFRAMEs, but a lot of people seem to block them now. We also wanna try and take advantage of the PR from google, with having them linking to us.

Can AJAX or whatever do anything like this?

TIA!

Andy
 
Hi

AJAX can request content only from the same domain as the page in which runs.

You can use [tt]object[/tt] instead of [tt]iframe[/tt], but essentially is the same. ( Excepting that old Explorer versions are unable to load HTML document in [tt]object[/tt]. )

Beside that, I not understood what are you trying to do.

Feherke.
 
Hi,

Mmm ok - well I found this post:


..but seeing as he says the "hole could be fixed up" ... not sure its a way I'd wanna go (as it would leave loads of sites not working) :(

All I wanna do, is give them a URL - like , and that would then grab a load of details from our site, and return the HTML.

TIA

Andy
 
If its all very basic then there's not much else you need to do.

From their side they could use several things like curl (on PHP) to open the site using your link, and the parse the contents of the delivered page as they see fit.

You could even produce an XML file, and let them use any xml parsing functions they have access to to get the information the way they wanted.

Basically from your side of the things, all you would need to do it just offer the information.

Its up to them to pick it up and use it.







----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Hi,

Mmm ok - well most of the people wouldn't wanna use curl or LWP::Simple::get()[in perl], as they are not very techie =))

Maybe just gonna have to rely using IFRAMEs :(

Thanks anyway guys

Cheers

Andy
 
I was able to get this to work as a test for myself. If I understand correctly exactly what you are trying to do, it's something like how sites like YOUTUBE allow you to embed videos on your site - you would like to provide the ability for people to embed something on their site streamed from your site - correct?

I placed a javascript file on a server (SERVER-A) and used it to grab the contents of a file on the same server.

On my local machine, I referenced the file on SERVER-A and populated a DIV tag on my local machine with the result.

I would post my code on this site, but I would rather you try the method out yourself to see if you can get it to work.

feherke - did I just luck out with it or is this actually possible across domains?


--------

GOOGLE is a great resource to find answers to questions like "how do i..."


--------
 
feherke - I used the XMLHTTPREquest object to grab the contents of the file from the javascript page on the server.

Code:
function getPageContents(strInput) {
	var strDocument;
	
	strDocument = "[URL unfurl="true"]http://mydomain.com/myfile.asp?myvar[/URL] = " + strInput;
	var objRequest;
	
	// mozilla browsers
	if (window.XMLHttpRequest) { 
	   objRequest = new XMLHttpRequest();
	   	if (objRequest.overrideMimeType) {
	       objRequest.overrideMimeType('text/xml');
	   }
	} 
	//ie browser
	else if (window.ActiveXObject) { 
	   try {
		    objRequest = new ActiveXObject("Microsoft.XMLHTTP")
    	} 
		catch (e) {
	       try {
    		   objRequest = new ActiveXObject("Msxml2.XMLHTTP");
   	   		} 
			catch (e) {
				alert("Sorry, your browser is not supported, pleae upgrade to IE 6+, Firefox or Safari");
			}
	   }
	}
	objRequest.onreadystatechange =  function() {return checkState(objRequest);}
	objRequest.open('GET', strDocument, true);
	objRequest.send(null);
return false;	
}

I reference this script from a different server and call the getPageContents() function passing in the value. This function then does it's thing and once I hit 4/200 I grab the the responsetext and populate a div on the client...

If the original poster would just reply to the question - do you want to do something like youtube where your client can post information on their site from your's, it could make it clearer - that's how I interpretted it, but I don't know for sure...


--------

GOOGLE is a great resource to find answers to questions like "how do i..."


--------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top