Iframe的Javascript替代方案
Javascript Alternative to Iframe?
我是一个在线角色扮演游戏的管理员,我们最近从某种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>
相关文章:
- 在Javascript中使用eval的替代方案
- 寻找使用Javascript从Kendo UI时间选择器中减去时间的更好替代方案
- 有没有javascript循环的替代方案
- 在Python中抓取javascript渲染的文本的最快解决方案
- 在IE8和其他带有javascript的浏览器中获取正文类的标准解决方案是什么
- 是否有用于CSS浏览器支持新功能的javascript解决方案
- 适用于年轻用户的 Javascript 提示框的替代方案
- Javascript全局变量简单解决方案
- JavaScript/HTML 错误的解决方案
- Javascript Learnstreet Email Interpreter 替代解决方案
- 正在寻找与以下jQuery解决方案等效的javascript解决方案
- JavaScript没有'JSP页面重定向后无法工作..任何解决方案
- 使用AJAX的Javascript/jQuery中的循环替代方案
- 在两个解决方案中引用通用的Javascript文件
- 用于回文变位的JavaScript解决方案
- windows中的Javascript巨大日期错误..解决方案
- 具有类似onhashchange的相同功能的JavaScript onopstate替代方案
- JavaScript 模块模式和它的替代方案有什么区别
- 深度嵌套函数的替代方案 javascript
- Jquery解决方案/ javascript函数分配变量