Jump to content

how to get external page source?


mikedikta

Recommended Posts

Hi, this is my first post (but not last), thanks for reading.Here's my problem: I want a site with two frames: the left one has a button, and the right one is an external site (eg: google.com).And I want (need) that when the button in the left frame gets clicked it saves the source code of the site in the right one. I need to get this source in a String or in a file or in some other way that I can manipulate it (I know I can't modify an external page, and that's not what I want)I did the following code, that works when the left frame is an internal file (ex: frame_02.htm), but does't work when I use http://google.com//this the main page<html><title>Exemplo de criação de frames</title><FRAMESET cols="50%,50%"> <FRAME SRC="frame1.htm" NAME="frame1"> <FRAME SRC="http://google.com" NAME="frame2"> //works if was "frame2.htm"</FRAMESET><body></body></html>//this is frame1.htm<html><title>Frist Frame</title><body><form name="view"><input type="button" name="source" onclick="vs()" value="View This Page's Source"></form><script language="Javascript"><!--// please keep these lines on when you copy the source// made by: Nicolas - http://www.javascript-page.comfunction vs() {document.location = "view-source:" + parent.frame2.document.location.href}//--></script></body></html>how can I have the source code of a external site? anyone could post a solution? can be in Java, or other languagethanks for readingbest regards

Link to comment
Share on other sites

Your code works for me in FF with the following changes:

<!-- FRAME SRC="http://google.com" NAME="frame2" --><FRAME SRC="http://google.com" id="frame2">

and

function vs() {//document.location = "view-source:" + parent.frame2.document.location.hrefdocument.location = "view-source:" + parent.document.getElementById("frame2").src}

But I don't think the view-source protocol works any more in IE: http://support.microsoft.com/default.aspx?...kb;en-us;904678

Link to comment
Share on other sites

You're better off using a server side scripting language to get the source there. In ColdFusion, you would use <cfhttp>, for example.

Link to comment
Share on other sites

Your code works for me in FF with the following changes:
<!-- FRAME SRC="http://google.com" NAME="frame2" --><FRAME SRC="http://google.com" id="frame2">

and

function vs() {//document.location = "view-source:" + parent.frame2.document.location.hrefdocument.location = "view-source:" + parent.document.getElementById("frame2").src}

But I don't think the view-source protocol works any more in IE: http://support.microsoft.com/default.aspx?...kb;en-us;904678

thanks, it works in firefox.but now i got this problem, the frame starts with google.com, but the user can open other url in the frame, I need to get the source of the current page being viewd
Link to comment
Share on other sites

thanks, it works in firefox.but now i got this problem, the frame starts with google.com, but the user can open other url in the frame, I need to get the source of the current page being viewd
Well, I don't remember seeing a way in your code for the user to open another url, but as long as you do it by setting the frame source when they enter a new url (parent.document.getElementById("frame2").src = newurl), then it continues to work.
Link to comment
Share on other sites

Well, I don't remember seeing a way in your code for the user to open another url, but as long as you do it by setting the frame source when they enter a new url (parent.document.getElementById("frame2").src = newurl), then it continues to work.
well, users can't input the url, but the first page has links to others, in fact its not google.com . Its other page (also external to my site) , that the user will fill in a form and them will apper the result, I want to get the source of this result page.got it?
Link to comment
Share on other sites

well, users can't input the url, but the first page has links to others, in fact its not google.com . Its other page (also external to my site) , that the user will fill in a form and them will apper the result, I want to get the source of this result page.got it?
I take it you're referring to the fact that if, for example, frame 2 src is www.google.com, and the user clicks the Maps link in that frame, the content changes but frame 2 src remains www.google.com and is not set to the new url for the Maps link. So accessing the src property is not giving what you need. However, with your original syntax you are up against browser security issues. (You're probably aware that browsers use a cross-domain security model to maintain separation between browser frames from different sources, to prevent code in one domain from accessing data in a different domain.) Personally I don't think you will get further with this approach. Maybe time for a rethink... what's the overall requirement, and can it be met a different way?
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...