问题描述
||
我已经下载了stackoverflow的索引页面作为示例,以在我的Web项目中显示它。在此项目中,我有一个IFrame,其中显示了页面的内容,但源代码阻止我在IFrame中显示它。现在我有两个问题:
我该如何克服这个问题? (注意:我不想在IFrame中显示stackoverflow.com,因此此网站没有安全问题)。
有没有更好的方法可以在另一个页面中显示HTML页面?
谢谢。
解决方法
您可以使用curl来获取URL的内容并显示它...
,我使用此PHP函数从该页面的源代码中删除了所有JavaScript:
function strip_javascript($filter,$allowed=0){
if(($allowed&1) == 0) // 1 href=...
$filter = preg_replace(\'/href=([\\\'\"]).*?javascript:.*?\\\\1/i\',\"\'\",$filter);
if(($allowed&2) == 0) // 2 <script....
$filter = preg_replace(\"/<script.*?>.*?<\\/script>/i\",\"\",$filter);
if(($allowed&4) == 0) // 4 <tag on.... ---- useful for onlick or onload
$filter = preg_replace(\"/<(.*)?\\son.+?=\\s*?([\'\\\"]).*?\\\\2/i\",\"<$1\",$filter);
return $filter;
}