php - iframe 跨域框架错误显示
问题描述
我正在使用 WordPress 进行开发,我的控制台面板将错误消息显示为
未捕获的 DOMException:阻止具有源“ https://demo.utrop.no ”的框架访问跨域框架。
当我访问 iframe 中的内容时会发生这种情况,下面的代码将显示我真正想要的内容。从这个 iframe 中,我需要获取正在加载到 WordPress 中 iframe 中的显示原始按钮的“a”标签详细信息。
<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>
解决方案
推荐阅读
- css - CSS: display: flex 和 text ellipsis 在同一个元素上
- android - Android TV 后退
- powerbi - PowerBi - 周数顺序不正确
- javascript - Node.js Promise 的函数参数
- bash - -bash: /var/lib/rancid/.bash_profile: 权限被拒绝 bash 命令未找到
- java - 如何使用sql提取源表?
- .htaccess - www.example.com 重定向到 https://www.www.example.com
- selenium - 我可以获得除范围报告以外的任何其他报告
- loops - 嵌套循环的大 O 时间复杂度
- python - 为什么soup.find('title') 在BeautifulSoup 中什么都不返回?