动态(2级)JavaScript / CSS加载IE6 [英] Dynamic (2 levels) Javascript/CSS Loading IE6

查看:61
本文介绍了动态(2级)JavaScript / CSS加载IE6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将js(和css)文件动态地包含在这样的网页中:
index.html-> loader_a.js-> a_foo.js,a_bar.js,a_foo.css等。

虽然这在FF中没有问题(使用appendChild),但我无法使其在IE6中运行。
我已经尝试了各种可用的解决方案(添加到dom节点,ajax调用和eval以及来自( http://ntt.cc/2008/02/10/4-ways-to-dynamic-load-external-javascriptwith-source.html )和那里以及其他类似帖子#2013676)

i am trying to dynamically include js (and css) files into a webpage like this: index.html -> loader_a.js -> a_foo.js, a_bar.js, a_foo.css and so on.
While this works without a problem in FF (using appendChild) i cant get it to run in IE6. I've tried various available solutions (adding to dom node, ajax call and eval and more from (http://ntt.cc/2008/02/10/4-ways-to-dynamically-load-external-javascriptwith-source.html) here and there and others like post #2013676) but it's not doing what its supposed to do.

当我使用DebugBar进行检查时,我发现我的包含文件(例如a_foo.js)实际上已加载,但其内容是空-在其他包含的文件(1级/直接)上显示此内容,所以我认为有问题...

When i check with DebugBar i see that my include files (eg a_foo.js) is actually loaded, but its content is empty - on other included files (1 Level/directly) this content is show so i assume there is the problem ...

我得到的错误始终是不确定的我调用的函数是o / cb / c的对象未正确加载,因此帮助不多。我没有在include上出现任何错误。

我已经验证了javascripts,所以那些应该没问题的人。

The "error" i get is alway undefined object which is o/c b/c the function i call is not loaded properly so not much of a help. I dont get any errors on the includes.
I've validated the javascripts so those whould be ok.

有人对它有最终的解决方案吗?这个?
我可以重新创建测试并发布一些代码(如果有帮助的话)。

Does anyone have the ultimate solution for this? I can recreate my tests and post some code if it helps.

感谢,
的问候,
Thomas的

Thanks, regards, Thomas

HTML示例:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<HTML lang=en><HEAD><TITLE>Test</TITLE>

<script type="text/javascript" src="mmtest_files/jquery-1.4.2.min.js"></script>

<script type="text/javascript" src="mmtest_files/multiload.js"></script>
<script type="text/javascript" >

function init2() {
  // using the data from the loaded js files
  var a= mmf("a");
  document.getElementById('status').innerHTML = "Variable set:" + a;

}

// magic...
include(['mmt.js'],init2);

</script>

<BODY >

<H2>Test me!</H2>
<SPAN id=status>status old</SPAN>

</BODY></HTML>

JS 1是答案1的重载

JS 1 is multiload from answer 1

JS2是一个测试,包括:

JS2 is a test include:

函数mmf(param)
{
return Called with + param;
}

function mmf(param) { return "Called with" + param; }

推荐答案

您需要在ie中使用document.write才能并行加载脚本。

You need to use document.write in ie, in order to load scripts in parallel.

请参阅:不阻塞地加载脚本

我有这样的脚本,顺便说一句:以异步顺序加载多个Javascript文件

I have such a script btw: Loading Multiple Javascript Files In Order Asynchronously

(在Chrome中可能需要进行一些改动)

(it may need some enchancements in Chrome)

UPDATE

有一个回调函数,它是可选的。它可用于将依赖脚本耦合到文件。 EG:

There is a callback function, it is optional. It can be used to couple dependent script to the files. EG:

function myjQueryCode() {
   // ...
}

include(['jquery.js','jquery-ui.js'], myjQueryCode);

这样,依赖于jquery的代码将在文件加载后运行。

So that your jquery dependent code will run after the files has been loaded.

这篇关于动态(2级)JavaScript / CSS加载IE6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆