Iframe的Javascript替代方案

Javascript Alternative to Iframe?

本文关键字:方案 Javascript Iframe      更新时间:2023-09-26

我是一个在线角色扮演游戏的管理员,我们最近从某种Frankencode过渡到了javascript。虽然我已经掌握了基本知识,但我遇到了一个问题,我不知道如何解决。

我们在游戏中有宏,你可以通过在方向上键入空格、分号和方向之间的另一个空格来移动多个房间。我创建了一个图集,里面有一长串宏,可以帮助游戏玩家更快、更高效地移动。我的主要问题是,一切都使用了Frankencode,但Javascript在我的新代码中无法识别iframe。

我真的很想有一个替代iframes的方案,在那里我不必依赖外部网站来编写这个脚本,但我进入这条充满希望的思路的旅程只导致了一堆鲜红色、愤怒的错误和命令中断。我用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;
}

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

了解Javascript的最佳页面来自Mozilla开发者网络,此链接将特别帮助您了解更多关于ajax的信息。

然而,也有一些库可以下载,比如jQuery,它可以帮助简化许多任务,包括加载和存储html等。

如果你需要存储一个网站,你可以做以下操作:

在HEAD:中包含jQuery

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