Click to See Complete Forum and Search --> : find text string in innerHTML (need PYRO to read)


llamatron
09-06-2003, 05:33 AM
I was using the following code supplied by the Moderator of this board Pyro (http://forums.webdeveloper.com/showthread.php?s=&threadid=16108) to find a certain value in a web pages HTML code:

function getid(){
code = document.getElementsByTagName("html")[0].innerHTML;
results = code.match(/member_id=(\d*)&/g);
for (i=0;i<results.length;i++) {
value = results[i].match(/member_id=(\d*)&/);
alert (value[1])
}
}

This works fine however the problem is that I need to find the code in a popup window not the main window where this code sits (the popup window is an external page i have no control over).

So I tried this :

function newin(){
newWindow = window.open('http://www.myurl.com', 'form_target','width=700, height=500, scrollbars=no,menubar=no,status=no,resizable=no,toolbar=no, titlebar=no,location=no,directories=no');
setTimeout("getid();",5000);
}

function getid(){
code = newWindow.document.getElementsByTagName("html")[0].innerHTML;
results = code.match(/member_id=(\d*)&/g);
for (i=0;i<results.length;i++) {
value = results[i].match(/member_id=(\d*)&/);
alert (value[1])
}
}

But I just get a javascript error. I know I can control newWindow in the getid() function because if i put the line newWindow.close() in getid() it closes the popup. So why can't i refer to it in the same way when running Pyro's code?
The only thing I can think of is the popup window page is not getting sufficent time to load fully, but the setTimeout function should avoid this right? Please help. Thanks

Mr J
09-06-2003, 06:24 AM
Is the url in the popup from your site?

llamatron
09-06-2003, 06:52 AM
The main page opens a popup page to an external site. I need to extract a code from the HTML source code of this external site.

llamatron
09-06-2003, 09:31 AM
From what I have found out, it seems that this is a security issue and you cannot extract a web pages html source if it is on a different domain using a scripting language like javascript. Does anyone know any different?
If not, Is it possible to do using php?

Khalid Ali
09-06-2003, 09:54 AM
you can use Java URL classes to open a URL and read it or write to it

llamatron
09-06-2003, 11:54 AM
I've discovered another way of getting my code. Is it possible, using Javascript, to get all the URL's on an external webpage and store them somewhere so that the string can be manipulated, as my code is also embedded in these. If so could someone let me know how?
Thanks again.