从脚本标签中加载external.JS脚本(可以dun)??? [英] Loading an external.JS script from within the script Tag (Can itbe dun)???

查看:74
本文介绍了从脚本标签中加载external.JS脚本(可以dun)???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部,

我想知道它们是否是一种从脚本中加载外部脚本填充的方式?


< script language = " JavaScript的" type =" text / javascript">

function test(var){

< script language =" javascript" SRC =" ../脚本/ base.js"类型= QUOT;文本/ JavaScript的" />

}

< / script>


显然这会导致n错误,但这会给你一个想法我正在做什么我知道我可以通过一个简单的包含来做到这一点但是...


抱歉这个愚蠢的问题...提前致谢。 - CES

All,
I was wondering if their is a way of loading an external script fill from within a script??

<script language="javascript" type="text/javascript">
function test(var){
<script language="javascript" src="../scripts/base.js" type="text/javascript" />
}
</script>

Obviously this would cause n error but this would give you an idea of what I''m looking to do. I know I can do this with a simple include but...

Sorry about the stupid question... Thanks in advance. - CES

推荐答案

CES在2005年11月20日下午6:12发表以下声明:
CES said the following on 11/20/2005 6:12 PM:
全部,的方法?


是的,它的好处是它得到的支持比

HTTPRequest对象更广泛。

<脚本语言= QUOT; JavaScript的"类型= QUOT;文本/ JavaScript的">


跳过语言属性。它与HTML无关,冗余和弃用



函数测试(var){
< script language =" javascript" src =" ../ scripts / base.js"
type =" text / javascript" />
}


如果你不使用var,为什么var会传入函数?但是,var是

可能是最差的变量名。

< / script>
显然这会导致n错误,但这会给你一个想法
我想做什么。我知道我可以用一个简单的包含但是...


看起来你想动态加载.js文件取决于

变量而不用重新加载页面。


< URL:
http://groups.google.com/group/comp=\"scoring%3Dd%26




或者,一个tinyURL:


< URL: http://tinyurl.com/a8kte >


这是我解释并得到反馈的线程,如何做你在b $ b描述的是什么。


-

兰迪

comp.lang.javascript常见问题 - http://jibbering.com/faq &新闻组每周

Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /



Or, a tinyURL:

<URL: http://tinyurl.com/a8kte >

Is a thread where I explained, and got feedback, on how to do what you
are describing.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Randy Webb写道:
Randy Webb wrote:
CES在2005年11月20日下午6:12发表以下内容:
CES said the following on 11/20/2005 6:12 PM:
全部,
我想知道它们是否是一种从脚本中加载外部脚本填充
的方法?
All,
I was wondering if their is a way of loading an external script fill
from within a script??


是的,其好处是它比HTTPRequest对象得到更广泛的支持。



Yes, and the benefit is that it is more widely supported than an
HTTPRequest Object is.

< script language =" javascript" type =" text / javascript">
<script language="javascript" type="text/javascript">



跳过语言属性。它与HTML无关,冗余和弃用。



Skip the language attribute. It''s irrelevant, redundant and deprecated
in HTML.

function test(var){
< script language =" javascript" src =" ../ scripts / base.js"
type =" text / javascript" />
}
function test(var){
<script language="javascript" src="../scripts/base.js"
type="text/javascript" />
}



如果你不使用var,为什么var会传入函数?但是,var可能是最糟糕的变量名。



Why is var passed into the function if you don''t use it? But, var is
probably the worst variable name to use.

< / script>
显然这会导致n错误,但这会给你一个想法
我想做什么。我知道我可以通过一个简单的包含来实现这一点但是......
</script>
Obviously this would cause n error but this would give you an idea of
what I''m looking to do. I know I can do this with a simple include but...



看起来你想根据一个变量动态加载.js文件而不重新加载页面。

< URL:
http://groups.google.com/group/comp....scoring%3Dd%26

>



或者,一个小小的URL:

< URL: http: //tinyurl.com/a8kte >

是我解释的一个帖子,并获得了feedba ck,关于如何做你正在描述的事情。



Or, a tinyURL:

<URL: http://tinyurl.com/a8kte >

Is a thread where I explained, and got feedback, on how to do what you
are describing.




兰迪,


抱歉愚蠢。 ..不幸的是,在我有机会撤回帖子之前你做出了回应......这就是我想在外部.js文件中做的事情:


--- -----外部文件base.js(文件大小为17kb)-------

var loadGoogleScript = document.createElement(''script'');

loadGoogleScript.type =" text / javascript" ;;

loadGoogleScript.src =" http://www.google-analytics.com/urchin.js" ;;


--------调用base.js的HTML -----------------

< head> ;

< script src =" ../ scripts / base.js"类型= QUOT;文本/ JavaScript的" />

< / head>

这似乎在IE中正确加载但我看到一些帖子表明这可能不适用于FireFox的任何建议?

另外我知道外部文件是异步加载的......在我从脚本中调用函数之前,它是否是一种测试脚本是否加载的方法?


CES



Randy,

Sorry for the stupidity... unfortunately you responded before I had a chance to retract the post... This is what I''m trying to do from within an external .js file:

--------external file base.js (File Size is 17kb)-------
var loadGoogleScript = document.createElement(''script'');
loadGoogleScript.type = "text/javascript";
loadGoogleScript.src = "http://www.google-analytics.com/urchin.js";

-------- HTML that calls the base.js -----------------
<head>
<script src="../scripts/base.js" type="text/javascript" />
</head>
This seems to load properly in IE but I''ve seen some posts that indicate this might not work in FireFox any Suggestions?
Also I know the external file loads asynchronously... is their a way of testing if the script has loaded before I call a function from within the script??

CES


Randy Webb写道:
Randy Webb wrote:
CES在2005年11月20日下午6:12发表以下内容:
CES said the following on 11/20/2005 6:12 PM:
全部,
我想知道他们是否是一种从脚本中加载外部脚本填充
的方法?
All,
I was wondering if their is a way of loading an external script fill
from within a script??



是的,其好处是它比HTTPRequest对象得到更广泛的支持。



Yes, and the benefit is that it is more widely supported than an
HTTPRequest Object is.

< script language =" javascript" type =" text / javascript">
<script language="javascript" type="text/javascript">



跳过语言属性。它与HTML无关,冗余和弃用。



Skip the language attribute. It''s irrelevant, redundant and deprecated
in HTML.

function test(var){
< script language =" javascript" src =" ../ scripts / base.js"
type =" text / javascript" />
}
function test(var){
<script language="javascript" src="../scripts/base.js"
type="text/javascript" />
}



如果你不使用var,为什么var会传入函数?但是,var可能是最糟糕的变量名。



Why is var passed into the function if you don''t use it? But, var is
probably the worst variable name to use.

< / script>
显然这会导致n错误,但这会给你一个想法
我想做什么。我知道我可以通过一个简单的包含来实现这一点但是......
</script>
Obviously this would cause n error but this would give you an idea of
what I''m looking to do. I know I can do this with a simple include but...



看起来你想根据一个变量动态加载.js文件而不重新加载页面。

< URL:
http://groups.google.com/group/comp....scoring%3Dd%26

>



或者,一个小小的URL:

< URL: http: //tinyurl.com/a8kte >

是我解释的一个帖子,并获得了feedba ck,关于如何做你正在描述的事情。



Or, a tinyURL:

<URL: http://tinyurl.com/a8kte >

Is a thread where I explained, and got feedback, on how to do what you
are describing.




抱歉...我忘了将appendChild加入上面的剧本:


--------外部文件base.js -------

var loadGoogleScript = document.createElement(''script'');

loadGoogleScript.type =" text / javascript" ;;

loadGoogleScript.src =" http://www.google-analytics.com/urchin.js" ;;

document.getElementsByTagName(''head'')[0] .appendChild(loadGoogleScript);


只是为了提升urchin.js文件的混乱大小是17kb,而不是base.js


如果有人能够解决上面的两个问题我会很高兴 - CES



Sorry... I forgot to ad the appendChild to the script above:

--------external file base.js -------
var loadGoogleScript = document.createElement(''script'');
loadGoogleScript.type = "text/javascript";
loadGoogleScript.src = "http://www.google-analytics.com/urchin.js";
document.getElementsByTagName(''head'')[0].appendChild(loadGoogleScript);

And just to elevate any confusion the urchin.js file size is 17kb, not the base.js

If anyone could anser the two questions above I wold be greatfull - CES


这篇关于从脚本标签中加载external.JS脚本(可以dun)???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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