Javascript to set cookie

拥有回忆 提交于 2019-12-29 08:24:35

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/23272632/javascript-to-set-cookie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!