2014-10-31 85 views
-3

我是一個在線角色扮演遊戲的管理員,我們最近從某種Frankencode轉換到JavaScript。儘管我已經掌握了基本知識,但是我遇到了一個我不確定如何解決的問題。Iframe替代iframe?

我們在遊戲中擁有宏,您可以通過在空間,分號和方向之間輸入空格來移動多個房間。我創建了一個有很長的宏列表的地圖集,以幫助遊戲玩家更快更高效地移動。我的主要問題是,一切與Frankencode一起工作,但Javascript並沒有在我的新代碼中識別iframe。

我真的很喜歡iframe的替代方案,我不需要依賴外部網站來編寫這個腳本,但是我進入那個充滿希望的思路的旅程剛剛導致了一堆明亮的紅色,憤怒的錯誤和命令打破。我用iframe替換了滿足表,遊戲就沒有了!

以下是我的代碼。請記住,除了iframe,一切都可以工作。

在此先感謝! :)

var macaroni = "<center><img src=http://i188.photobucket.com/albums/z46/roseblossomsnapdragon/items/atlas.jpg><BR><image src= http://i188.photobucket.com/albums/z46/roseblossomsnapdragon/amazingatlas-1.jpg~original><BR/> <b><font color=blue><u><b>IF ANY OF THESE ARE BROKEN, INFORM VICTORIA.</font></u></b></b><BR> <table border=0> <tr> <td Valign=top bgcolor=white> <IFRAME name=inlineframe src=http://karchanhelp.webs.com/other%20stuff/otherotherstuff/macaroni.htm width=550 height=400 marginwidth=0 marginheight=0 frameborder=0 scrolling=auto></IFRAME></td> <td Valign=top bgcolor=white><form method=post action=> <textarea name=comments cols=80 rows=21> Copy and paste here to build longer macros. </textarea> </form></td> </tr> </table><P> </center>"; 
 
var macaroons = "<center><img src=http://i188.photobucket.com/albums/z46/roseblossomsnapdragon/items/atlas.jpg><BR><image src= http://i188.photobucket.com/albums/z46/roseblossomsnapdragon/amazingatlas-1.jpg~original><BR/> <b><font color=blue><u><b>IF ANY OF THESE ARE BROKEN, INFORM VICTORIA.</font></u></b></b><BR> <table border=0> <tr> <td Valign=top bgcolor=white> <IFRAME name=inlineframe src=http://karchanhelp.webs.com/other%20stuff/otherotherstuff/macaroni.htm width=550 height=400 marginwidth=0 marginheight=0 frameborder=0 scrolling=auto></IFRAME></td> <td Valign=top bgcolor=white><form method=post action=> <textarea name=comments cols=80 rows=21> Copy and paste here to build longer macros. </textarea> </form></td> </tr> </table><P> </center>"; 
 

 
function command(person, totalcommand) { 
 
if (person.isAttribute("macaroons")) 
 
{ 
 
person.personal(macaroons); 
 
person.sendMessage("%SNAME begin%VERB2 studying an atlas out of nowhere.<BR>"); 
 
return; 
 
} 
 
person.personal(macaroni); 
 
person.sendMessage("%SNAME begin%VERB2 studying an atlas out of nowhere.<BR>"); 
 
return; 
 
}

+2

實際的問題是什麼?你說這與iframe有關,並且你爲iframe顯示了一些HTML,但是你並沒有真正解釋javascript問題是什麼。你是什​​麼意思「JavaScript不識別iframe」? – jfriend00 2014-10-31 06:31:16

回答

0

於Iframe另一種方法是AJAX(Asynchronos JavaScript和XML),它可以讓你從服務器加載頁面和數據,你可以處理的結果,並插入迴響應進入你的頁面。

瞭解Javascript的最佳頁面來自Mozilla開發人員網絡,this link尤其會幫助您瞭解有關ajax的更多信息。

然而,你可以下載的庫,如jQuery,可以幫助簡化很多任務,包括加載和存儲HTML等。

如果你需要存儲一個網站,你可以做到以下幾點:

包括jQuery的在HEAD:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 

創建(用於存儲或其他容器),一個div與任何ID你想要的(應該是唯一的):

<div id="loadingArea"></div> 

包括一個腳本在頁面的尾部或頭部以確保jQuery已加載

<script> 
    $(document).ready(//Will run the following function when the html document is ready 
     function() { 
      var url = "http://karchanhelp.webs.com/other%20stuff/otherotherstuff/macaroni.htm"; //Load the page you want. 
      var portion = "body >" //select the portion of the page you need to eliminate duplicate html, head, and body tags 
            //This is a jQuery selector similar to css meaning select all children (>) of body 

      //Here we tell jQuery to select the element with id(#) loadingArea and load the 
      //portion of the url. 
      $('#loadingArea').load(url+" "+portion); 
     } 
    ); //End of ready call 
</script>