IE6下动态载入JS脚本解决方案
[i=s] 本帖最后由 游戏人间 于 2010-3-12 01:52 PM 编辑 [/i]function GetJsonLoad()
{
var script = document.createElement("script");
script.src = globallUrl;
script.id = "script";
script.type = "text/javascript";
if (document.all)
{
script.onreadystatechange = function()
{
if (this.readyState == "complete" || this.readyState == "loaded")
{
if (typeof xx != 'undefined')
{
// 这里就可以正常的使用JS中的变量了
// 只可惜IE下好像并不能马上使用
// 而如果用setInterval让这个函数执行两次的话第二次就能OK了
// 谁有使用经验,因为是跨子域了并且需要登录,所以AJAX回调数据的方案或用代理都有点小困难
}
}
}
}
// 这里已经把其它可以用onload的浏览器部分代码删除了
document.body.appendChild(script);
} 尝试一下jquery的getScript [i=s] 本帖最后由 游戏人间 于 2010-3-12 11:36 AM 编辑 [/i]
我们用的prototype,我都在怀疑是prototype影响的
后来有人说是“当该js数据是no-cache, no-store,并且是gzip压缩的时候就会出现这个问题” [url]http://www.javaeye.com/topic/543572[/url]
郁闷了... 这个加载编辑器倒挺有用 让加载的那个JS执行当前页面的函数不就可以了 [quote]让加载的那个JS执行当前页面的函数不就可以了
[size=2][color=#999999]fly512 发表于 2010-3-12 13:41[/color] [url=http://www.phpx.com/redirect.php?goto=findpost&pid=1146328&ptid=259291][img]http://www.phpx.com/images/common/back.gif[/img][/url][/size][/quote]
一样的不行 [quote]
一样的不行
[size=2][color=#999999]游戏人间 发表于 2010-3-12 01:51 PM[/color] [url=http://www.phpx.com/redirect.php?goto=findpost&pid=1146330&ptid=259291][img]http://www.phpx.com/images/common/back.gif[/img][/url][/size][/quote]
不要用document.body.appendChild(script);
试下:
var head = document.getElementsByTagName("head")[0] || document.documentElement;
head.insertBefore( script, head.firstChild ); 怎么可能呢?看演示
[url]http://www.gaomaozi.com/test/request.html[/url]
向 [url]http://64.71.167.22/test/server.php[/url] 发请求
返回的header 信息
[code]
Server nginx/0.7.61
Date Fri, 12 Mar 2010 09:38:17 GMT
Content-Type text/html
Transfer-Encoding chunked
Connection keep-alive
X-Powered-By PHP/5.1.6
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Content-Encoding gzip
[/code] 我的也是IE6 [i=s] 本帖最后由 游戏人间 于 2010-3-12 06:14 PM 编辑 [/i]
你这是页面载入的时候就执行的。
我那是页面载入完成后,由客户端的用户点击某些东西之后去动态载入一段JS,这段JS是由另一子域下生成的json。
而且还是跨子域的,我不知道你直接用IP的方式是不是被JS认为已经是同一个域下。至少我测试的结果是跨子域的情况下AJAX是不行的(IE6)。
这是有差别的. :dizzy: 我用的不是AJAX,我那是跨域,就是创建一个script 去请求 [i=s] 本帖最后由 未注册会员 于 2010-3-12 08:38 PM 编辑 [/i]
装了IE8,没有测试环境。Jquery源码里:
// [color=#ff0000]Use insertBefore instead of appendChild to circumvent an IE6 bug.[/color]
// This arises when a base node is used (#2709 and #4378).
head.insertBefore( script, head.firstChild );
页:
[1]