我正在做一个桌面应用程序,我可以用AppJS在iframe中过滤一些特定的div。我有一个问题,我不能隐藏一些div,有一个代码:
<!DOCTYPE html>
<html>
<style>
</style>
<head>
<link type="text/css" rel="stylesheet" href="style.css" />
<script>
function resizeIframe(newHeight)
{
document.getElementById('iframe1').style.height = parseInt(newHeight,10) + 10 + 'px';
}
</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
</head>
<body onload='parent.resizeIframe(document.body.scrollHeight)'>
<h1>hello world</h1>
<iframe name='iframe1' id="iframe1" src="http://www.example.com" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 100%;"></iframe>
<script>
$(function(){
var f=$('#iframe1')
f.load(function(){
f.contents().find('div').hide();
})
})
</script>
</body>
</html> 我在控制台不安全的JavaScript尝试访问带有URL的帧时出错。
有可能解决这个问题吗?
发布于 2012-11-08 16:25:24
由于Cross-Domain Policy的原因,您不能直接这样做。
但是,您可以首先使用php脚本从您自己的服务器(代理)获取目标url的内容,然后将其内容加载到javascript/jquery中。这只是一个小小的修复,并不适合你想要加载的所有页面。
例如:
<iframe src="path_to_my_server_php_script/iframe.php?url=http://example.com"></iframe>iframe.php basic代码:{你也可以在这里设置头部或者操作html代码}
<?php
$url = $_GET['url'];
$html = file_get_contents($url);
echo $html;
?>发布于 2012-12-06 03:23:20
在create window调用中添加一个选项以关闭安全性:
disableSecurity:true
有关示例,请参阅维基页面:https://github.com/appjs/appjs/wiki/app-object
此设置应关闭跨域策略。
https://stackoverflow.com/questions/13285054
复制相似问题