2016-08-05 58 views
-1

我正在嘗試將aloha注入裝有iframe的頁面。這是我head標籤的內部HTML:將aloha注入iframe

<title>Getting Started with Aloha Editor</title> 
<link rel="stylesheet" href="/Styles/aloha.css" /> 
<script src="/Scripts/aloha/require.js"></script> 
<script src="/Scripts/aloha/aloha.js" data-aloha-plugins="common/ui,common/format,common/highlighteditables,common/link,common/image"></script> 
<script type="text/javascript"> 
    $(function() { 
     $("#email-template").load(function() { 
      var link = this.contentWindow.document.createElement("link"); 
      link.rel = "stylesheet"; 
      link.href = "/Styles/aloha.css"; 
      this.contentWindow.document.body.appendChild(link); 
      var script = this.contentWindow.document.createElement("script"); 
      script.type = "text/javascript"; 
      script.src = "/Scripts/aloha/require.js"; 
      this.contentWindow.document.body.appendChild(script); 
      script = this.contentWindow.document.createElement("script"); 
      script.type = "text/javascript"; 
      script.src = "/Scripts/aloha/aloha.js"; 
      script["data-aloha-plugins"] = "common/ui,common/format,common/highlighteditables,common/link,common/image"; 
      this.contentWindow.document.body.appendChild(script); 
      script = this.contentWindow.document.createElement("script"); 
      script.type = "text/javascript"; 
      script.innerHTML = '$(function() {Aloha.ready(function() {Aloha.jQuery(".editable-content").aloha();})});'; 
      this.contentWindow.document.body.appendChild(script); 
     }); 
    }); 
</script> 

這是我body標籤的內部HTML:

<div id="main"> 
    <table> 
     <thead> 
      <tr> 
       <th>Name</th> 
       <th>Value</th> 
      </tr> 
     </thead> 
     <tbody> 
      <tr> 
       <td>From</td> 
       <td><strong>[email protected]</strong></td> 
      </tr> 
      <tr> 
       <td>To</td> 
       <td><strong class="editable-content">[email protected]</strong></td> 
      </tr> 
      <tr> 
       <td>CC</td> 
       <td><strong class="editable-content">[email protected]</strong></td> 
      </tr> 
      <tr> 
       <td>Subject</td> 
       <td><strong>Please read this (not) really important email</strong></td> 
      </tr> 
      <tr> 
       <td>Content</td> 
       <td><iframe id="email-template" src="<%= ResolveUrl("~/Forms/Integration/Remedy/SandboxAlohaInner.aspx") %>"></iframe></td> 
      </tr> 
     </tbody> 
    </table> 
</div> 
<script type="text/javascript"> 
    Aloha.ready(function() { 
     Aloha.jQuery('.editable-content').aloha(); 
    }); 
</script> 
<asp:Button ID="Send" runat="server" Text="Send" /> 

一切外頁上很好,但在iframe不承認阿羅哈變數內頁。爲什麼?

錯誤消息如下:

Uncaught ReferenceError: Aloha is not defined

回答

0

我已經能夠解決這個問題。問題是,當我試圖達到它時,Aloha變量還沒有創建。解決的辦法是這個非常醜陋的黑客:

script.innerHTML = 'var alohaInterval = setInterval(function() {if (typeof Aloha === "undefined") {return;} clearInterval(alohaInterval); Aloha.ready(function() {Aloha.jQuery(".editable-content").aloha();})}, 100);'; 

,而不是在head所示load事件倒數第二排。