Reputation: 1241
I'm making a desktop app where i can filter some specificed div inside of iframe with AppJS. I'm having a problem i couldn't hide some divs, there is a code:
<!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>
I got errors from console Unsafe JavaScript attempt to access frame with URL
Is possible to fix that?
Upvotes: 0
Views: 1169
Reputation: 416
Add an option to the create window call to turn off security:
disableSecurity:true
See wiki page for an example: https://github.com/appjs/appjs/wiki/app-object
This setting should turn off the cross-domain policy.
Upvotes: 1
Reputation: 74420
You cannot do it directly because of Cross-Domain Policy.
However, you can first get content of the targeted url using php script from your own server (proxy) and then load its content in javascript/jquery. This is just a little fix and is not suitable for all kind of page you wish to load.
For example:
<iframe src="path_to_my_server_php_script/iframe.php?url=http://example.com"></iframe>
iframe.php basic code: {You could set headers or manipulate html code here too}
<?php
$url = $_GET['url'];
$html = file_get_contents($url);
echo $html;
?>
Upvotes: 1