1.function include_js(file) {
2. var _doc = document.getElementsByTagName('head')[0];
3. var js = document.createElement('script');
4. js.setAttribute('type', 'text/javascript');
5. js.setAttribute('src', file);
6. _doc.appendChild(js);
7.
8. if (!/*@cc_on!@*/0) { //if not IE
9. //Firefox2、Firefox3、Safari3.1+、Opera9.6+ support js.onload
10. js.onload = function () {
11. alert('Firefox2、Firefox3、Safari3.1+、Opera9.6+ support js.onload');
12. }
13. } else {
14. //IE6、IE7 support js.onreadystatechange
15. js.onreadystatechange = function () {
16. if (js.readyState == 'loaded' || js.readyState == 'complete') {
17. alert('IE6、IE7 support js.onreadystatechange');
18. }
19. }
20. }
2. var _doc = document.getElementsByTagName('head')[0];
3. var js = document.createElement('script');
4. js.setAttribute('type', 'text/javascript');
5. js.setAttribute('src', file);
6. _doc.appendChild(js);
7.
8. if (!/*@cc_on!@*/0) { //if not IE
9. //Firefox2、Firefox3、Safari3.1+、Opera9.6+ support js.onload
10. js.onload = function () {
11. alert('Firefox2、Firefox3、Safari3.1+、Opera9.6+ support js.onload');
12. }
13. } else {
14. //IE6、IE7 support js.onreadystatechange
15. js.onreadystatechange = function () {
16. if (js.readyState == 'loaded' || js.readyState == 'complete') {
17. alert('IE6、IE7 support js.onreadystatechange');
18. }
19. }
20. }
本文介绍了一种使用JavaScript动态加载外部JS文件的方法,并考虑了不同浏览器间的兼容性问题。针对Firefox、Safari、Opera及IE等浏览器的不同特性,提供了相应的解决方案。

5000

被折叠的 条评论
为什么被折叠?



