基本上IE浏览器记得网站www.stackoverflow.com使用JavaScript的cookies,但无论如何,手动在InnoSetup中代表stackoverflow.com创build一个相同的cookie?
Javascript cookie:
function setCookie(cname,cvalue,exdays) { var d = new Date(); d.setTime(d.getTime()+(exdays*24*60*60*1000)); var expires = "expires="+d.toGMTString(); document.cookie = cname + "=" + cvalue + "; " + expires; } function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; i<ca.length; i++) { var c = ca[i].trim(); if (c.indexOf(name)==0) return c.substring(name.length,c.length); } return ""; } function checkCookie(user) { var user=getCookie("username"); if (user!="") { alert("Welcome again " + user); } else { user='bandwidth - set to off for example'; setCookie("username",user,30); } }
注意:因为如果我的插件是安装的,没有办法从IE中检测。 我想到了,我必须要处理cookies。 但是,而不是IE我的插件必须创build该cookie第一次安装。
编辑:参考
更改Cookie域
访问HttpServletResponse cookie
apache如何dynamic使用“Header Set Set-Cookie expires = <date>”
当ajax使用apache mod_proxy和不同的域调用nodejs时会话
在使用Windows身份validation的MVC 4 Intranet站点上的cookie中保留用户首选项
http://msdn.microsoft.com/en-us/library/windows/desktop/aa385107%28v=vs.85%29.aspx
Magento + Nginxcaching+货币select器
以编程方式在Internet Explorer中设置Cookie
Nginx:仅基于cookie将用户redirect到特定的URL
HttpPost请求与Cookie
如何用C ++中的FastCGI(Nginx)创build一个cookie
要创建与指定的URL关联的cookie,您可以使用InternetSetCookie函数。 要检索指定的URL的cookie,您可以使用InternetGetCookie函数。 下面是他们翻译的一个例子,展示了如何创建和读取一个cookie(真正的代码实现,讨论错误消息,或者包含在你身上的包装函数;以下面的代码为例,展示如何使用这些API函数):
[Setup] AppName=My Program AppVersion=1.5 DefaultDirName={pf}My Program [Code] #ifdef UNICODE #define AW "W" #else #define AW "A" #endif const ERROR_INSUFFICIENT_BUFFER = 122; ERROR_NO_MORE_ITEMS = 259; function InternetSetCookie(lpszUrl: string; lpszCookieName: string; lpszCookieData: string): BOOL; external 'InternetSetCookie{#AW}@wininet.dll stdcall'; function InternetGetCookie(lpszUrl: string; lpszCookieName: string; lpszCookieData: string; var lpdwSize: DWORD): BOOL; external 'InternetGetCookie{#AW}@wininet.dll stdcall'; function TryCreateCookie(const URL,Name,Data: string): Boolean; begin // try to create a specified cookie Result := InternetSetCookie(URL,Data); // if the function call Failed,we can optionally report the reason why if not Result then MsgBox('Cookie creation Failed!' + #13#10 + SysErrorMessage(DLLGetLastError),mbError,MB_OK); end; function TryRetrieveCookie(const URL,Name: string; out Data: string): Boolean; var S: string; BufferSize: DWORD; begin // initialize function result Result := False; // initialize buffer size to 0 to query needed buffer size BufferSize := 0; // first call is to determine whether there's a requested cookie,or if so,// to retrieve the needed buffer size if not InternetGetCookie(URL,#0,BufferSize) then begin // the function Failed as expected,so let's inspect the reason case DLLGetLastError of // if the reason for failure was the insufficient buffer,it means that // there's a cookie matching the request and that we have just received // the required buffer size ERROR_INSUFFICIENT_BUFFER: begin // initialize buffer size by the prevIoUsly returned size SetLength(S,BufferSize div SizeOf(Char)); BufferSize := Length(S); // and call the function again,Now with the initialized buffer; this // time it should succeed; if it is so,then... if InternetGetCookie(URL,S,BufferSize) then begin // everything went fine,so let's return success state and assign a // retrieved value to the output parameter Result := True; Data := S; end else // the second function call Failed; that should not happen... MsgBox('Cookie retrieval Failed!' + #13#10 + SysErrorMessage(DLLGetLastError),MB_OK); end; // this code is returned when there's no cookie found ERROR_NO_MORE_ITEMS: begin // no cookie matching the criteria was found; the return value of this // function has already been initialized to False but it's upon you to // react on this fact somehow,if needed end; else // the first function call Failed for unexpected reason MsgBox('Cookie search Failed!' + #13#10 + SysErrorMessage(DLLGetLastError),MB_OK); end; end; end; procedure InitializeWizard; var CookieData: string; begin // try to create cookie TryCreateCookie('http://example.com','MyCookie','TestData=1234; expires=Wed,31-Dec-2014 23:59:59 GMT'); // try to retrieve cookie if TryRetrieveCookie('http://example.com',CookieData) then MsgBox(CookieData,mb@R_322_4045@ion,MB_OK); end;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。