开发者

How could I get the HTTP status from an Iframe?

开发者 https://www.devze.com 2023-03-24 02:30 出处:网络
I need to check if it´s been possible to load an external page on a website, and display an alert depending on that result.

I need to check if it´s been possible to load an external page on a website, and display an alert depending on that result.

I have an Iframe, and I have been triying to detect the HTTP error code with Jqu开发者_如何学Goery, and I couldn't find the way, does anybody knows how?

Thank you.


If you are trying to get content from some other domain, like for ex. from exampleA.com to exampleB.com using ajax, it will not work. Cross domain ajax request is prohibited by browser policy.

The same will go with iframe too. If you have an iframe which loads content from some other domain, you can not manipulate the content of the iframe using javascript.

A possible solution would be to use a server side proxy script. You need to write a server side script which loads the external website's content and you can request the script using ajax. As the script is running from your domain, you can request it from ajax.

If you are using php, you can use curl to load the external website's content from your php proxy script and call the proxy script using ajax.


I would use Ajax (with the help of some backend coding to actualy check the status) for that.

0

精彩评论

暂无评论...
验证码 换一张
取 消