Javascript替代Iframe?

时间:2014-10-31 06:23:57

标签: javascript iframe

我是在线角色扮演游戏的管理员,我们最近从某种Frankencode转换为javascript。虽然我已经掌握了基础知识,但我遇到了一个问题,我不确定如何修复。

我们在游戏中有宏,您可以通过在方向之间键入空格,分号和另一个空格来移动多个房间。我创建了一个包含很长宏列表的地图册,以帮助游戏玩家更快更有效地移动。我的主要问题是,一切都与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;
}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

iframe的替代方案是AJAX(Asynchronos Javascript和XML),它允许您从服务器加载页面和数据,您可以处理该结果并将响应插回到您的页面中。

了解Javascript的最佳页面来自Mozilla开发者网络,this link特别有助于您了解有关ajax的更多信息。

但是你可以下载一些库,例如jQuery,它们可以帮助简化很多任务,包括加载和存储html等等。

如果您需要存储网站,可以执行以下操作:

在HEAD中包含jQuery:

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

使用您想要的任何ID(应该是唯一的)创建div(或其他容器以进行存储):

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