A common AJAX technique is to return straight HTML and use the
innerHTML element attribute to insert it into the DOM. Unfortunately,
JavaScript inserted into the DOM this way (inside a <script> tag)
will not execute in all browsers.
I found this out when trying to implement a dynamically changing PlotKit
graph on my companies intranet site. It worked in Firefox (of course) and IE was coaxed into working be using the DEFER attribute
.
But the best Safari could do was leave a big blank space where my
beautiful graph should be. Even though there was probably only one
other employee that used Safari, I knew there was no way this was going
to stand. There must be a solution, right?
Some googling turned up this posting
,
where the problem was solved using a combination of cloneNode(),
innerHTML and appendChild(). Fancy. It works with Opera and IE, but not with Safari
.
Then, my eureka moment came. I replaced the <script> tag in
the RPC with a <div class=”javacript”> tag, still keeping all the
script inside the <div>. Next, I added .javascript { display: none; }
to the style sheet and did some jQuery magic:
$('#ajaxLoading').ajaxStop(function() {
$('.javascript').each(function() {
eval($(this).text());
});
});
This simple function runs every time an AJAX call is completed and
uses eval() to manually run the JavaScript. It’s ugly, it’s probably
violating some sort of standard, but guess what? It works in Safari
.
分享到:
相关推荐
NULL 博文链接:https://wuzhengxuan.iteye.com/blog/1263906
解决ajax返回innerHTML中javascript不能运行问题
js中innerHTML与innerText的用法与区别js中innerHTML与innerText的用法与区别
innerHTML的简单应用
改变文字innerHTML每个HTML元素具有InnerHtml属性定义的HTML代码和文字之间发生的元素的开幕式和闭幕式标记。...下面我们来看一个用js的innerHTML来改变div值吧. 代码如下:<script type=”text/javascript
innerHTML的使用document.getElementById("id").innerHTML = "contenttext";
js中innerHTML与innerText的用法与区别
调用innerHTML之后,onclick失效了,这也是在意料之中的,因为innerHTML是以文本形式插入的button,所以无法识别onclick事件
简单日历和innerHTML使用 javascript的简单应用实例 可以自定义Css
在用innerHTML生成结构时,为了看起来...innerHTML中标签可以换行的方法</title> </head> <body> [removed] //function fnNew(){ var sHtml = ''; for(var i = 0; i < 2 xss=removed class=in>\
博文链接:https://aideqianfang.iteye.com/blog/246585
然而,你需要知道 innerHTML 有一些自身的问题: 1、当 HTML 字符串包含一个标记为 defer 的 script 标签([removed]…[removed])时,如 innerHTML 属性处理不当,在 Internet Explorer 上会引起脚本...
本文实例讲述了Javascript中innerHTML用法。分享给大家供大家参考。 具体实现方法如下: 代码如下:<html> <head> [removed] function t(){ var cont = document.getElementById(‘container’); ...
主要介绍了javascript中innerHTML 获取或替换html内容,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
显示innerHTML 和 outterHTML
主要介绍了用原生 JS 实现 innerHTML 功能,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
网站中使用了一个js插件,设置innerHTML时,在IE8下报错“未知运行时错误”: <a> -->报错处 第三方插件内容… 原因: 所设置的innerHTML的对象是一个,是由于的对象包容性的比较低,当浏览器运行这段脚本...