Javascript设置cookie [英] Javascript to set cookie
问题描述
我尝试让javascript设置一个cookie,告诉Google翻译哪种语言来设置页面。我选择了基于浏览器的Cookie
< script>
$(document).ready(function(){
setcookie(googtrans,/ en / fr,time()+ 3600,/,www.example .com);
setcookie(googtrans,/ en / fr,time()+ 3600,/,.example.com);
}
< / script>
我对javascript不是很好,我得到了一个意外的令牌ILLEGAL,不知道这是什么意思:
< script>(function(){with(this [2]){with(This [1]){with (this [0]){return function(event){ccm_exitVersionList()
};}}}})< / script>
我的脚本是否错误?任何帮助感谢。
JavaScript字符串必须用 QUOTATION MARK)或
'
(APOSTROPHE)不(左双引号标记)和
此错误通常是由使用自动插入印刷引号的文字处理程序编写代码造成的。
使用为程序员设计的文本编辑器(例如Sublime,Vim,Emacs,Komodo,TextMate,Notepad ++,BBEdit或Eclipse)。
I am trying to have a javascript set a cookie that tells Google Translate which language to set the page.
I have tried this based on my browser's cookie when selecting a language.
<script>
$(document).ready(function(){
setcookie("googtrans", "/en/fr", time()+3600, "/", "www.example.com");
setcookie("googtrans", "/en/fr", time()+3600, "/", ".example.com");
});
</script>
I am not very good with javascript and I get an unexpected token ILLEGAL, not sure what this means:
<script>(function() {with (this[2]) {with (this[1]) {with (this[0]) {return function(event) {ccm_exitVersionList()
};}}}})</script>
Is my script wrong? Any help appreciated.
JavaScript strings must be quoted with "
(QUOTATION MARK) or '
(APOSTROPHE) not "
(LEFT DOUBLE QUOTATION MARK) and "
(RIGHT DOUBLE QUOTATION MARK).
This error is typically caused by writing code using a word processor that automatically inserts typographic quotes.
Use a text editor designed for programmers (such as Sublime, Vim, Emacs, Komodo, TextMate, Notepad++, BBEdit, or Eclipse) instead.
这篇关于Javascript设置cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!