PDA

View Full Version : Copying content of a frame


cutovoi
07-08-2004, 02:27 PM
Hi for all

I'm trying to copy the content of a frame and save it into a txt file, but I can't do this. I would like to select this frame: "<frame src="caminho2.html" name="c2" noresize>".
My frame's code:
<html>
<head>
<script language="JavaScript" type="text/javascript">
function copiar(qframe)
{
var freime_nome = null;
var freimes = parent.getElementByTagName('frame')
window.alert(freimes)
for(var i=0;i<=freimes.lenght;i++)
{
if(freimes[i].type == 'frame')
{
if(freimes[i].name == "c2" || window.frames[i].id == "c2")
{
freime_nome = freimes[i].name;
i = freimes.lenght + 1;
}
}
}
window.alert("eee"+ " "+freime_nome)
var frme = eval("window."+freime_nome)
window.alert(qframe)
frme.focus()
frme.select()
setTimeOut("copiar(c2.select)",5000)
}
</script>
</head>
<frameset rows = "23%,77%" onLoad="copiar(c2.select)">
<frame src="caminho.html" name="c1" noresize scrolling="no">
<frame src="caminho2.html" name="c2" noresize>
</frameset>
</html>
Please, can anyone helps me?


tks agent002 for help in my answer....

agent002
07-08-2004, 04:38 PM
No problem. About the previous question, I mean.

However, there are two major problems with your request.
1) Getting the text only is tricky - I don't know any better way (that is simple enough) than .innerText. The problem is that innerText only works in Internet Explorer and Opera, and it doesn't maybe get the text formatted as you want.

2) Saving the text file is even trickier. This requires an ActiveX control and ActiveX is only supported by Internet Explorer (and other browsers where an ActiveX plugin has been installed... there aren't almost any at all). Besides, because ActiveX is a major security risk, most people have it disabled. So in the end, there will only be a small minority that is able to use this function at all.

So, before I try putting something together, I'd like to ask what purpose you need it for, and if it really is necessary?

cutovoi
07-09-2004, 07:05 AM
Ok man, I'll answer your question:

I have created a webpage with two frames. In the first, person insert some word and when she clicks in search button(located in caminho.src's frame), another webpage is loaded(Google, Altavista, Yahoo)into caminho2.src's frame, with the surveyed word. After the page is loaded JavaScript copies the content of caminho2.src's frame and save in a text file. More yet, after this, it starts a excel macro(this, after all, I made....hehehe), that opens the ".txt" file, count in what line this word appears.

Well, it is.....


Tks for any help

agent002
07-09-2004, 07:32 AM
You just got yourself a bigger problem :D
See, if the page in the other frame (caminho2) isn't located on the same domain as the page trying to access it, you get a JavaScript security error. And because there's a Google or Yahoo search result in the frame, you obviously can't read the contents of it...

cutovoi
07-09-2004, 08:04 AM
So, how can I copy the content?

agent002
07-09-2004, 08:32 AM
If the page is hosted on another domain... e.g. google.com or yahoo.com, then I'm afraid there's no way.

cutovoi
07-09-2004, 09:02 AM
ok, I was thinking to do this in another way, how can I activate a Internet Explorer command? Then, I can execute the command: CTRL+A, and after CTRL+V command to paste.