iframe跨域框架错误显示

时间:2019-12-30 07:01:07

标签: php wordpress curl iframe

我正在使用WordPress进行开发,并且“我的控制台”面板将错误消息显示为

未捕获到的DOMException:阻止了起源为“ https://demo.utrop.no”的框架访问跨域框架。

这是在我访问iframe中的内容时发生的,下面的代码将显示我的实际需求。从此iframe中,我需要获取显示原始按钮的'a'标签详细信息,该按钮正被加载到WordPress的iframe中。

<iframe src="" style="width: 400px; height: 200px;" id="myFrame" name="iframe_a"></iframe>

<a href="https://www.retriever-info.com/go/?a=79334&d=00233220191223303391398&p=1861654&s=2332&sa=2044493&x=fe0e0a14ee1e6ad2107d665284c5082c" target="iframe_a">W3Schools.com</a>

<input type="button" id="btn" value="click" onclick="myFunction()">

<?php
    global $wpdb;
    $url = 'https://www.retriever-info.com/go/?a=79334&d=00233220191223303391398&p=1861654&s=2332&sa=2044493&x=fe0e0a14ee1e6ad2107d665284c5082c'; 
    $ch = curl_init($url);
    curl_setopt($ch,
        CURLOPT_HTTPHEADER,
        array(

            'Content-Type:application/xml',
            'Authorization: 79334',
        )
    );
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);

    $html = curl_exec($ch); 
    $redirectedUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
    echo "Original: $url <br>Final: $redirectedUrl";
    $opts = array(
        'http' => array(
            'method'=>"GET",
            'header'=>"Content-Type: text/html; charset=utf-8"
        )
    );



    $ch = curl_init();
    curl_setopt($ch,
        CURLOPT_HTTPHEADER,
        array(

            'Content-Type:application/xml',
            'Authorization: 79334',
        )
    );

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 50);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );

     $html = curl_exec($ch); 




        $dom = new DOMDocument();
        @$dom->loadHTML($html);
        $xpath = new DOMXPath($dom);
        $href = $xpath->evaluate("/html/body//a");
        echo '<pre>';
            print_r($html);
        echo '</pre>';
        for ($i = 0; $i < $href->length; $i++) {
            $data = $href->item($i);
            $url = $data->getAttribute('href');

            echo "Successful Link Harvest: ".$url.'<br>';
        }

      curl_close($ch);

   ?>





<script>

    function myFunction() {
      var iframe = document.getElementById("myFrame");
      var elmnt = iframe.contentWindow.document.getElementsByTagName("a")[0];
      console.log(elmnt)

</script>

0 个答案:

没有答案