[英]window.sessionStorage issue in IE, when webpage is not run on localhost
I've created a login webpage that sends a userId and password to a Java servlet via javascript. 我创建了一个登录网页,该网页通过javascript将userId和密码发送到Java servlet。 When the servlet validates the credentials, it sends a response to the webpage, and I store the userName in sessionStorage by using:
当servlet验证凭据时,它将响应发送到网页,然后使用以下命令将用户名存储在sessionStorage中:
sessionStorage.userId=uName; //read uName from servlet & save userId for this session
After this, I navigate to a new page by using window.location.replace("home.html")
, and in home, I read userId
for further use. 此后,我使用
window.location.replace("home.html")
导航到新页面,然后在家里阅读userId
以供进一步使用。
I'm using Apache Tomcat v8.0 on Windows . 我在Windows上使用Apache Tomcat v8.0 。
I'm running my login page on the browser via: 我正在通过以下方式在浏览器上运行登录页面:
localhost:8080/login.html
10.11.12.13:8080/login.html
(from my machine's IP, given in ipconfig
) 10.11.12.13:8080/login.html
(来自我机器的IP,在ipconfig
给出) The setup works fine in Chrome and Firefox for both localhost and IP. 对于本地主机和IP,该设置在Chrome和Firefox中均可正常运行。
However, in IE11, sessionStorage works correctly only when I use localhost:8080. 但是,在IE11中, 仅当我使用localhost:8080 时 ,sessionStorage 才能正常工作。 When I supply the IP address,
sessionStorage.userId
doesn't retain its value. 当我提供IP地址时,
sessionStorage.userId
不会保留其值。
Since IE is working fine for localhost, I know that Window.sessionStorage is supported by IE. 由于IE在本地主机上运行良好,因此我知道IE支持Window.sessionStorage。
I've also tried saving the userId in a separate .js file, but that value is lost as soon as the page navigates. 我也尝试将userId保存在单独的.js文件中,但是一旦页面导航,该值就会丢失。
Any suggestion would be earnestly welcomed. 任何建议都将受到热烈欢迎。 Thanks
谢谢
I found my answer on: Local website renders differently using (IP address or machine name) vs localhost? 我在以下位置找到了答案: 本地网站使用(IP地址或计算机名称)与本地主机呈现的方式有所不同?
Turns out, that the issue was with my html, not my javascript. 原来,问题出在我的html,而不是我的javascript。 I added this line in my head tag:
我在head标签中添加了以下行:
<meta http-equiv="X-UA-Compatible" content="IE=11">
and that fixed it. 并解决了它。
Don't know if this helps but there was a time where console only was available if you had devtools open which lead to some exceptions and not working code. 不知道这是否有帮助,但是如果您打开了devtools,有时会导致只有控制台可用,这会导致某些异常而不是有效的代码。
Do you use the latest version of ie11? 您是否使用最新版本的ie11?
Maybe this also helps: JavaScript localStorage object broken in IE11 on Windows 7 也许这也有帮助: Windows 7上的IE11中的JavaScript localStorage对象损坏
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.