2012-11-08 29 views
0

我正在製作一個桌面應用程序,我可以使用AppJS過濾iframe中的某些特定div。我有一個問題,我無法掩飾一些div,有一個代碼:AppJS - 不安全的JavaScript嘗試訪問框架的網址

<!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

可以解決這個問題訪問了幀錯誤?

+0

js無法在正常情況下完成任務.... –

回答

1

由於Cross-Domain Policy,你不能直接做。

但是,您可以先從您自己的服務器(代理)使用php腳本獲取目標url的內容,然後將其內容加載到javascript/jquery中。這只是一個小小的修復,並不適合您希望加載的所有頁面。

例如:

<iframe src="path_to_my_server_php_script/iframe.php?url=http://example.com"></iframe> 

iframe.php基本代碼:{您可以設置頁眉或操縱這裏的html代碼太}

<?php 
    $url = $_GET['url']; 
    $html = file_get_contents($url); 
    echo $html; 
?> 
+0

您是否有片段可以從我的服務器獲取使用php腳本的目標內容?謝謝! – Ivan

+1

查看我的基本代碼更新 –

+0

這是瘋了,什麼是在我的桌面應用程序中執行的web瀏覽器策略 – KJW

相關問題