0

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?

1
  • js cannot accomplish task under normal condition.... Commented Nov 8, 2012 at 8:31

2 Answers 2

1

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;
?>
Sign up to request clarification or add additional context in comments.

2 Comments

Do you have a snippet to get content of the targeted using php script from my server? Thanks!
this is insane, what is a web browser policy doing in my desktop app
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.