How to get iframe content from a remote page?

落花浮王杯 提交于 2019-12-04 10:48:31

You won't be able to access the document of a remote page inside an iframe using javascript because of the same origin policy.

If you know the URL of the page you can use PHP CURL to retrieve it

<?php 
        // Initialise a cURL object
        $ch = curl_init(); 

        // Set url and other options
        curl_setopt($ch, CURLOPT_URL, "http://page-with-some-iframe.com");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

        // Get the page contents
        $output = curl_exec($ch); 

        // close curl resource to free up system resources 
        curl_close($ch);  

It is not possible because of security policy. If you are able to get contents of remote iframe - you can steal someone's facebook or banking data with ease. Thats why all web browsers blocks this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!