在页面上注入脚本的一些有趣的方面...... [英] Some interesing aspect of injecting scripts on page...

查看:49
本文介绍了在页面上注入脚本的一些有趣的方面......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

简单的问题(但因此可能看起来不是简单的答案):

如果我把一个脚本放到页面上我只需要在
< script>元素或通过其src属性所以(第二种方式):

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

< / script>

,我的问题很简单

我应该使用什么编码在写我的时候使用

crossBrowserDegradationLib.js:

a)它应该与我的网页编码相同的编码(和

相同在meta标签中注明)?

b)应该是其他(如US-ASCII)吗?


请回复:)

Hi !
Simple question (but thus it may appear no simple answer):
If i putting a script onto the page i simply could inline it in
<script> element or via its src attribute so (second way):
<script type="text/javascript" src="js/crossBrowserDegradationLib.js">
</script>
, my question is simple
What encoding should i use when writting my
crossBrowserDegradationLib.js:
a) should it be the same encoding like encoding of my web page (and the
same as noted in meta tags) ?
b) should it be other (like US-ASCII) ?

Please reply :)

推荐答案




Luke Matuszewski写道:



Luke Matuszewski wrote:

< ; script type =" text / javascript" src =" js / crossBrowserDegradationLib.js">
< / script>
,我的问题很简单
在编写我的
crossBrowserDegradationLib.js时我应该使用什么编码:
a)它是否应该像我的网页编码一样编码(和元标记中的注释相同)?
b)它应该是其他的(如US-ASCII)吗?
<script type="text/javascript" src="js/crossBrowserDegradationLib.js">
</script>
, my question is simple
What encoding should i use when writting my
crossBrowserDegradationLib.js:
a) should it be the same encoding like encoding of my web page (and the
same as noted in meta tags) ?
b) should it be other (like US-ASCII) ?




请注意,HTML 4规范为脚本元素定义了名为charset

的属性

< http ://www.w3.org/TR/html4/interact/scripts.html#h-18.2.1>

所以你总能做到

<脚本类型=" text / javascript"

src =" file.js"

charset =" putCharacterEncodingNameOfFile.jsHere">< / script>

让浏览器知道编码。

当然,您可以设置服务器以使用HTTP发送文件

Content-Type标头包含charset参数。


所以编码对于脚本文件是您的选择还是选择

脚本文件的作者,它可以与HTML

文件的编码不同,唯一重要的是沟通如上所述,编码到

浏览器。


-


Martin Honnen
< a rel =nofollowhref =http://JavaScript.FAQTs.com/target =_ blank> http://JavaScript.FAQTs.com/


Luke Matuszewski写道:
Luke Matuszewski wrote:
嗨!
简单的问题(但因此可能看起来没有简单的答案):
如果我把一个脚本放到页面上我只是可以在
< script>中内联它元素或通过其src属性所以(第二种方式):
< script type =" text / javascript" src =" js / crossBrowserDegradationLib.js">
< / script>
,我的问题很简单
在编写我的
crossBrowserDegradationLib.js时我应该使用什么编码:
a)它是否应该像我的网页编码一样编码(和元标记中的注释相同)?
b)它应该是其他的(如US-ASCII)吗?
Hi !
Simple question (but thus it may appear no simple answer):
If i putting a script onto the page i simply could inline it in
<script> element or via its src attribute so (second way):
<script type="text/javascript" src="js/crossBrowserDegradationLib.js">
</script>
, my question is simple
What encoding should i use when writting my
crossBrowserDegradationLib.js:
a) should it be the same encoding like encoding of my web page (and the
same as noted in meta tags) ?
b) should it be other (like US-ASCII) ?




相当奇怪的问题......我猜你应该从ECMA的书籍开始你的教育了;然后是这些;-)

尽管在回答现代世界的问题时他们有时会出错或有雾,但对于像这样的基本事情,他们

仍然非常有帮助。特别建议你阅读

Book of Source,第1章,进一步说明:

< http://developer.mozilla.org/js/specs/ ecma-262#a-6>


关于你之前关于构造函数和对象的问题:

似乎(可能是错误的)你试图解释JavaScript来自

仅限于JavaScript本身。

我邀请您查看限定符public,protected,

private,static和最终的用其他OOP语言(不一定是
Java!)并尝试在JavaScript中使用它们的模拟或模拟。它

有很大帮助。 :-)


关于新问题(即 - 关于创建新对象的能力)。它是
首次在Netscape 2.0的最新更新中测试过,它是在Netscape 3.0中正式推出的




它是有趣的是注意到在Netscape的原始版本中

3.0你不能为一个变量指定一个对象引用,这个变量是用原始语言初始化的



var foo =" bar";

foo = new Image(60,60);

会导致参数错误。

var foo = null;

foo = new Image(60,60);

会好起来的。


AFAYK到目前为止,它是JavaScript中任何类型化的第一次和最后一次尝试

。在查看古代代码时,您可能会注意到

未来的参考持有者初始化为null。



Rather strange question... I guess you should start your education from
the Books of ECMA then ;-)
Despite they may get sometimes wrong or foggy when answering on
questions of the modern world, but for basic things like this one, they
are still very helpful. In the particular I suggest you to read the
Book of Source, Chapter 1 and further:
<http://developer.mozilla.org/js/specs/ecma-262#a-6>

Concerning your previous questions about constructors and objects: it
seems (possibly wrong) that you are trying to explain JavaScript from
within JavaScript itself exclusively.
I invite you then to take a look at qualifiers "public", "protected",
"private", "static" and "final" in other OOP language (not necessary
Java!) and try to fing their analogs or emulations in JavaScript. It
helps a lot. :-)

About "new" question (namely - about ability to create new objects). It
was first tested on the last update on Netscape 2.0 and it was
officially introduced in Netscape 3.0.

It is interesting to notice that in the original release of Netscape
3.0 you couldn''t assign an object reference to a variable which was
initialized with a primitive:
var foo = "bar";
foo = new Image(60,60);
would lead to "Argument error".
var foo = null;
foo = new Image(60,60);
would go fine.

AFAYK up to now it was the first and the last attempt of any typezation
in JavaScript. While looking through ancient codes you may notice that
the future reference holders are initialized with null.




Martin Honnen写道:

Martin Honnen wrote:
请注意,HTML 4规范为脚本元素定义了一个名为charset
的属性
< http://www.w3.org/ TR / html4 / interact / scripts.html#h-18.2.1>
所以你总是可以做
< script type =" text / javascript"
src =" file。 js"
charset =" putCharacterEncodingNameOfFile.jsHere">< / script>
因此脚本文件的编码是您的选择或者选择
脚本文件的作者,它可以与HTML
文档的编码不同,唯一重要的是将编码传递给
浏览器,如上所述。
Note that the HTML 4 specification defines an attribute named charset
for the script element
<http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.1>
so you can always do
<script type="text/javascript"
src="file.js"
charset="putCharacterEncodingNameOfFile.jsHere"></script>
So the encoding for the script file is your choice or the choice of the
script file author, it can differ from the encoding of the HTML
document, the only important thing is to communicate the encoding to the
browser as explained above.



在规格世界中,我同意:)但''charset''是可选属性 - 如果

那么t母鸡将使用哪种编码来解码脚本

(假设Content-Type没有发送,即使它被发送然后

i know(来自某些rfc)网络服务器的默认字符集是

ISO-8859-1)...

最后我意识到''正常''服务器将内容 - 输入并因此设置为ISO-8859-1的
字符集(参见
http://www.cert.org/tech_tips/malici...gation.html#3) ...


所以通常如果省略charset属性,标准ISO-8859-1

用于解码:-)


最佳问候公开讨论。

卢克。


In specs world i agree :) but ''charset'' is optional attribute - and if
so then which encoding would be taken by browser to decode the script
(let as assume that Content-Type isn''t send and even if it is sent then
i know (from some rfc) that default charset for web servers is
ISO-8859-1)...
Finally i realize that ''normal'' server sents the Content-Type and thus
charset set to ISO-8859-1 (see
http://www.cert.org/tech_tips/malici...gation.html#3)...

So typically if we omit the charset attribute the standard ISO-8859-1
is used for decoding :-)

Best regards for open discussion.
Luke.


这篇关于在页面上注入脚本的一些有趣的方面......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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