f



Access denied in javascript when try to see contents of page in javascript opened window

Hello

I am trying to write some javascript that will open a new web-page in
a new window and then be able to determine if the web-page that has
been opened contains certain text.

I am opening the new window with:
	newpage = window.open("http://www.somewebaddress.com/
index.html","newpage","width=400,height=200,left=400,top=300,resizable=1,status=1,scrollbars=1");

I am then trying to see if it contains certain text by using:
	if(newpage.document.getElementsByTagName('body')[0].innerHTML = =
"text") alert("contains the text");

However this line seems to produce an error that says "Access denied".

Does anyone know why this is or another way of achieving my goal?

Thanks

AM

0
admyc (8)
9/3/2007 10:32:55 PM
comp.lang.javascript 38369 articles. 2 followers. javascript4 (1315) is leader. Post Follow

2 Replies
836 Views

Similar Articles

[PageSpeed] 45

En r�ponse � admyc qui �crivit, en date du :  4/09/07 0:32, le message 
suivant :
> Hello
> 
> I am trying to write some javascript that will open a new web-page in
> a new window and then be able to determine if the web-page that has
> been opened contains certain text.

It is absolutly forbiden to acces to contain of another domain ... !

So your browser doesn't allow you to parse the page displayed in your 
popup because probably this page comes from another domain.

Test with a file comming from your own site
to see if your script is right.


> I am opening the new window with:
> 	newpage = window.open("http://www.somewebaddress.com/
> index.html","newpage","width=400,height=200,left=400,top=300,resizable=1,status=1,scrollbars=1");
> 
> I am then trying to see if it contains certain text by using:
> 	if(newpage.document.getElementsByTagName('body')[0].innerHTML ==
> "text") alert("contains the text");
> 
> However this line seems to produce an error that says "Access denied".

Acces denied to the other site's contain .... !

-- 
ASM
0
ASM
9/3/2007 11:02:04 PM
admyc wrote:
> I am trying to write some javascript that will open a new web-page in
> a new window and then be able to determine if the web-page that has
> been opened contains certain text.
> 
> I am opening the new window with:
> 	newpage = window.open("http://www.somewebaddress.com/
> index.html","newpage","width=400,height=200,left=400,top=300,resizable=1,status=1,scrollbars=1");

`newpage' should be declared with `var'.  The window name (second argument)
should be distinguishable in order not to reuse windows from other sites.
As for the third argument, omit "left=...,", "top=...,", and all `=1'.

> I am then trying to see if it contains certain text by using:
> 	if(newpage.document.getElementsByTagName('body')[0].innerHTML = =
> "text") alert("contains the text");
> 
> However this line seems to produce an error that says "Access denied".
> 
> Does anyone know why this is or another way of achieving my goal?

http://www.google.com/search?as_q=%22Same+Origin+Policy%22&filter=0
http://groups.google.com/groups?as_q=Same+Origin+Policy&as_ugroup=comp.lang.javascript&scoring=d&filter=0


PointedEars
-- 
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
0
Thomas
9/4/2007 12:29:36 AM
Reply: