2013-10-30 42 views
3

我正在與我的客戶做一個項目,在這個項目中我想在​​瀏覽器的單個頁面上打開多個網站,爲此我使用iframe,但是我在openerp框架中卡住了。在iframe我也設置了openerp屏幕,但問題是,當我創建一個客戶,一旦它達到創建時間,嚮導不會打開。關於iframe的替代選項?

某些代碼是在這裏:

<iframe src="http://localhost:8069" name="mainFrame" > 

我想知道的替代來

+5

iframes通常用戶體驗不好。使用普通的HTML元素並動態改變它的內容thoguth AJAX。另外,請考慮閱讀[問]並訪問[幫助]。如果我理解正確,你的問題可能會更好。 「請給我」在這裏一般被認爲是粗魯的 - 短語你的問題以及..一個問題。 –

+0

,但只是遠離使用ajax時存在的跨域問題 –

+0

檢查了這一點http://stackoverflow.com/questions/15146578/alternative-to-iframe-to-pull-in-actual-data-from-an -external-website-or-form –

回答

3

我發現這個在這個崗位 - 可能是值得一試 - http://jsfiddle.net/rWwRL/

Alternative to iFrames with HTML5

<object data="http://www.web-source.net" width="600" height="400"> 
    <embed src="http://www.web-source.net" width="600" height="400"> </embed> 
    Error: Embedded data could not be displayed. 
</object> 
1

我想y您可以同時使用jQuery load

<div id="divId"></div> 
<script type='text/javascript'> 
    $(document).ready(function(){ 
     $('#divId').load(URL of target);  
    }); 
</script> 
1

您可以使用Ajax或jQuery作爲替代iframe中。我覺得jQuery會簡單得多。你可以簡單地實現它:

$('#SampleElement').load('YourURL'); 

這裏,SampleElement是給定元素的ID。

3

出於安全原因,在瀏覽器中通過javascript訪問多個網站的能力受到嚴重限制。我打算將這個想法顯示爲通過javascript if iframe模仿器顯示其他網頁。對於這種應用,我會成立三類網站:

  1. 主機站點:在主機站點,一個IFRAME模仿可以用一個簡單的Ajax請求進行。這是孩子的東西。
  2. 第一方網站(除主機以外):在這裏您可以訪問服務器配置(或至少可以修改標題),您將需要指定頭Access-Control-Allow-Origin: "host site name here"允許主機網站的訪問或Access-Control-Allow-Origin: *任何網站允許每個網站的訪問權限。
  3. 第三方網站:在第三方網站的你將有希望網站的Access-Control-Allow-Origin頭被設置爲*,否則你將需要說服該網站的管理員破例,讓你的網站的訪問。

如果上述條件都不能滿足,那麼您將受到用戶瀏覽器安全性的制約。有些瀏覽器支持CORS(跨源資源共享),但它不可靠。通常,用戶的瀏覽器阻止訪問某些標題(出於安全原因),但是如果瀏覽器提供支持(或具有足夠寬鬆的安全性),則可以設置標題以誘騙其他網站讓您訪問。請注意,如果允許的話,有些人可能會考慮這種邊界線黑客行爲,如果沒有相關各方的許可,可能不應該使用它。

$(document).ready(function(){ 
    var target_domain = "example.com"; 
    var protocol = "http://"; 
    var path = ""; //e.g. "/index.html" 
    var target_host = protocol + target_domain; 
    var target_URI = target_host + path; 
    var method = "GET"; 
    $.ajax({ 
     url: target_URI, 
     type: method, 
     headers: { 
      "X-Requested-With": "", //nullifies the default AJAX value of "XMLHttpRequest" 
      "Origin": target_host, //lies to the target server 
      "Referer": target_host, //lies to the target server 
      "X-Http-Method-Override": method, //forces the specified method 
     }, 
     crossDomain: "true" //applies cross domain settings 
    }); 
}); 
$(document).ajaxSuccess(function(){ 
    $("#iframe_imitator").html(xhr.responseText); 
});