检测浏览器

编程入门 行业动态 更新时间:2024-10-27 07:30:12
本文介绍了检测浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

请问,为什么这不起作用? < SCRIPT language = JavaScript type =" text / javascript"> var br =''< SCRIPT language = Javascript'' br + =''src =" js_pop.js" type =" text / javascript">'' br + =''< / SCRIPT>'' var op =''< SCRIPT language = Javascript'' op + =''src =" js_pop-op.js" type =" text / javascript">'' op + =''< / SCRIPT>'' if(navigator.userAgent.indexOf(''' Opera'')!= -1){ document.write(op) } else { document.write(br) } // - > < / SCRIPT> 我拉了一个JS圣经中具有相同结构的脚本: 函数重写(){ var newContent = a ??< HTML>< HEAD>< ; TITLE>新文件< / TITLE>< / HEAD> a ?? newContent + = a ??< BODY BGCOLOR = a ?? aquaa ??>< H1>这文件是全新的。< / H1> a ?? newContent + = a ??点击后退按钮查看原始文件.a ?? newContent + = a ??< / BODY>< / HTML> a ?? document.write(newContent) } 什么''我的建筑错了?错误消息我在IE中说 未终止的字符串常量..而另一个奇怪的是该部分 的脚本出现在页面的最顶部,这就是出现的情况: " var op =" ( http:// www.francesdelrio/hbl/index2.html ) 感谢您的帮助.... Frances

pls, why is this not working? <SCRIPT language=JavaScript type="text/javascript"> var br = ''<SCRIPT language=Javascript'' br += ''src="js_pop.js" type="text/javascript">'' br += ''</SCRIPT>'' var op = ''<SCRIPT language=Javascript'' op += ''src="js_pop-op.js" type="text/javascript">'' op += ''</SCRIPT>'' if (navigator.userAgent.indexOf(''Opera'') != -1 ) { document.write(op) } else { document.write(br) } //--> </SCRIPT> I pulled a script with an identical construction from the JS Bible: function reWrite() { var newContent = a??<HTML><HEAD><TITLE>A New Doc</TITLE></HEAD>a?? newContent += a??<BODY BGCOLOR=a??aquaa??><H1>This document is brand new.</H1>a?? newContent += a??Click the Back button to see original document.a?? newContent += a??</BODY></HTML>a?? document.write(newContent) } what''s wrong with my construction?? error msg I get in IE says "undeterminated string constant".. and the other weird thing is that part of the script appears at the very top of the page, this is what appears: " var op = " (www.francesdelrio/hbl/index2.html) thank your for any help.... Frances

推荐答案

>请问,为什么这不起作用? > pls, why is this not working? < SCRIPT language = JavaScript type =" text / javascript"> var br =''< SCRIPT language = Javascript'' br + =''src =" js_pop.js" type =" text / javascript">'' br + =''< / SCRIPT>'' var op =''< SCRIPT language = Javascript'' op + =''src =" js_pop-op.js" type =" text / javascript">'' op + =''< / SCRIPT>'' if(navigator.userAgent.indexOf(''Opera'')!= -1 ){ document.write(op)} else { document.write(br)} // - > < / SCRIPT> 我从JS圣经中提取了一个具有相同结构的脚本: 函数reWrite(){ var newContent = a ??< HTML> ;< HEAD>< TITLE>新文件< / TITLE>< / HEAD> a ?? newContent + = a ??< BODY BGCOLOR = a ?? aquaa ??>< H1> ;这个文件是全新的。< / H1> a ?? newContent + = a ??点击Back按钮查看原始文件.a ?? newContent + = a ??< / BODY>< / HTML> a ?? document.write(newContent)} 我的构造有什么问题?错误消息我在IE中说未终止的字符串常量...而另一个奇怪的是脚本的部分出现在页面的最顶部,这就是出现的内容: var op =" <SCRIPT language=JavaScript type="text/javascript"> var br = ''<SCRIPT language=Javascript'' br += ''src="js_pop.js" type="text/javascript">'' br += ''</SCRIPT>'' var op = ''<SCRIPT language=Javascript'' op += ''src="js_pop-op.js" type="text/javascript">'' op += ''</SCRIPT>'' if (navigator.userAgent.indexOf(''Opera'') != -1 ) { document.write(op) } else { document.write(br) } //--> </SCRIPT> I pulled a script with an identical construction from the JS Bible: function reWrite() { var newContent = a??<HTML><HEAD><TITLE>A New Doc</TITLE></HEAD>a?? newContent += a??<BODY BGCOLOR=a??aquaa??><H1>This document is brand new.</H1>a?? newContent += a??Click the Back button to see original document.a?? newContent += a??</BODY></HTML>a?? document.write(newContent) } what''s wrong with my construction?? error msg I get in IE says "undeterminated string constant".. and the other weird thing is that part of the script appears at the very top of the page, this is what appears: " var op = "

当浏览器看到 br + =''< / SCRIPT>'' 它愚蠢地认为< / SCRIPT>是脚本的结尾。那么看到的编译器是什么? br + ='' 看起来像一个未终止的字符串常量并且脚本的其余部分是以文本形式显示的。这样做的道理是你必须弄清楚关闭脚本 标签,这样浏览器就不会那么愚蠢。我建议在>之前插入\ 。其他人喜欢把它放在斜线之前。我认为最好将 放在>之前。因为这也解决了XML CDATA的相关问题。 br + =''< / script\>''; jslint检查这个。 www.crockford/javascript/lint.html 摆脱// - >。这是浪费空间。最新款式是在标签中使用 小写。

When the browser sees br += ''</SCRIPT>'' it stupidly thinks that </SCRIPT> is the end of the script. So what the compiler sees is br += '' which looks like an unterminated string constant and the rest of the script is displayed as text. The moral of that is that you must dirty up the close script tag so that the browser will not behave so stupidly. I recommend inserting a \ before the >. Others like to put it before the slash. I think it is better to put it before the > because that also solves a related problem with XML CDATA. br += ''</script\>''; jslint checks for this. www.crockford/javascript/lint.html Get rid of the //-->. It is a waste of space. The latest style is to use lowercase in the tags.

" Frances Del Rio" < FD *** @ yahoo>在消息中写道 news:op ************** @ news.cis.dfn.de ... 当网络浏览器找到一个开头脚本标签,如: - "Frances Del Rio" <fd***@yahoo> wrote in message news:op**************@news.cis.dfn.de... When a web browsers finds an opening script tag like:- < SCRIPT language = JavaScript type =" text / javascript"> 它必须决定发送给JavaScript 解释器后面的内容。它通过寻找 - < / SCRIPT>来做到这一点。 - 在HTML中。 var br =''< SCRIPT language = Javascript'' br + =''src =" js_pop.js" type =" text / javascript">'' 它在此处找到: - br + =''< / SCRIPT>' ' <SCRIPT language=JavaScript type="text/javascript"> It has to decide how much of what follows to send to the JavaScript interpreter. It does that by looking for - </SCRIPT> - in the HTML. var br = ''<SCRIPT language=Javascript'' br += ''src="js_pop.js" type="text/javascript">'' And it finds it here:- br += ''</SCRIPT>''

要在JavaScript字符串中使用结束HTML脚本标记,您需要 使其看起来像其他内容。使用转义字符可以 有效 - < \ / script> - 或< / script\> - 。 < snip> Richard。

To use the closing HTML script tag in a JavaScript string you need to make it look like something else. Using escape characters can be effective - <\/script> - or </script\> -. <snip> Richard.

7月2日2003 13:26:19 +0200,Lasse Reichstein Nielsen < lr*@hotpop>写道: On 02 Jul 2003 13:26:19 +0200, Lasse Reichstein Nielsen <lr*@hotpop> wrote: " Douglas Crockford" <无**** @ laserlink>写道: "Douglas Crockford" <no****@laserlink> writes: 其他人喜欢把它放在斜线之前。我认为最好把它放在>之前。因为这也解决了XML CDATA的相关问题。 br + =''< / script\>''; Others like to put it before the slash. I think it is better to put it before the > because that also solves a related problem with XML CDATA. br += ''</script\>'';

最令人惊讶的事情就是它有效。根据规范,终止脚本内容的是结束标记打开,即< /。

The most suprising thing is that it works. According to specification,what terminates the script content is the "end tag open", i.e., "</".

我认为它的工作原理是因为浏览器中的纠错,他们看到了ETAGO,但是因为它没有跟着SCRIPT>然后他们知道 这不是作者的意图。 吉姆。 - comp.lang.javascript常见问题 - jibbering/faq/

I think it works because of error correction in the browser, they see the ETAGO, but because it''s not followed by SCRIPT> then they know it''s not what the author intended. Jim. -- comp.lang.javascript FAQ - jibbering/faq/

更多推荐

检测浏览器

本文发布于:2023-08-02 18:59:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1280288.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:浏览器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!