【发布时间】:2014-06-16 23:11:48
【问题描述】:
localstorage 似乎适用于: - 谷歌浏览器 - 火狐浏览器 - 歌剧 - 歌剧迷你 - 可能是 Safari
但不在 Internet Explorer 上(我使用的是 Internet Explorer 11)。我的是windows 7。 我需要能做同样工作的等价物。这是一个项目,我在我的 C: 驱动器上做所有事情(安全性并不重要)所以我的协议是文件:\。我做了一些研究,有些人通过添加来解决它:
<!DOCTYPE html>
但它对我不起作用。
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
* {
font-family:Cambria;
color:blue;
}
</style>
</head>
<body>
<script>
function transfer() {
confirm("Would you like to save your password for this site?");
var contents = document.getElementById('email_input').value;
var contents_2 = document.getElementById("password_input").value;
localStorage.setItem('user', contents);
localStorage.setItem('password', contents_2);
window.location.href = 'page2.html';
};
var button_clicked = function(){
email_content = document.getElementById("email_input").value;
pass_content = document.getElementById("password_input").value;
points = 0;
if (email_content.length < 1){
document.getElementById("empty_1").innerHTML = ("*please input your email address");
} else {
document.getElementById("empty_1").innerHTML = ("<br>");
points += 1;
};
if (pass_content.length < 1){
document.getElementById("empty_2").innerHTML = ("*please input your password");
} else {
document.getElementById("empty_2").innerHTML = ("<br>");
points += 1;
};
if (points === 2){
transfer();
}
};
</script>
<div id="top_bar" style="height:100px;background-color:lightslategray;">
<marquee scrollamount="20" behavior="scroll"><p style="font-size:30px;color:white;">
Welcome, please login to your account to continue</p>
</marquee>
</div>
<div>
<div style="margin-left:500px;width:300px;height:200px;background-color:lightblue;"></div>
<div style="margin-left:440px;">
<div style="background-color:whitesmoke;width:350px;height:270px;margin-left:30px;border-radius:15px;
margin-bottom:30px;">
<div style="margin-left:40px;">
<h1>Login below</h1>
<p id="empty_1" style="color:red;"><br></p>
<p>Email address: <input id="email_input" type="text" style="width:150px;"/></p>
<p id="empty_2" style="color:red;"><br></p>
<p>Password: <input id="password_input" type="password" style="width:180px;"/></p>
<br>
<button onclick="button_clicked()">Submit</button>
</div>
</div>
</div>
<div style="margin-left:500px;width:300px;height:500px;background-color:lightblue;"></div>
</div>
</body>
</html>
另存为page1.html 第二页是:
<!DOCTYPE html>
<html>
<head>
<title id='title'>title goes here</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type='text/css'>
h1 {
color:blue;
}
</style>
</head>
<body>
<h1 id='my_title'>Title</h1>
<h2 id='my_pass'>Title</h2>
<script>
var full_name = localStorage.getItem('user');
list = [];
for (i=0;i<full_name.length;i++){
if (full_name[i]==="@"){
break;
}
else{
list.push(full_name[i]);
}
};
document.getElementById("my_title").innerHTML = ("Name: " + list.join(""));
var full_pass = localStorage.getItem('password');
document.getElementById("my_pass").innerHTML = ("Email address: " + full_name);
</script>
</body>
</html>
另存为page2.html
感谢所有答案。
【问题讨论】:
-
IE的版本是多少?
-
你用的是什么操作系统?
-
如果您使用的是 IE 11,请确保将其修补到最新版本(Windows 更新),因为在 Win7 SP1 的初始版本中存在错误,并且本地存储无法按预期工作。 stackoverflow.com/a/21156133/3535297
-
@Wolfdog 检查您的 IE 版本 单击浏览器顶部的菜单,直到您看到“关于 Internet Explorer”的内容,我无法告诉您确切的位置,因为我不知道是什么您正在使用的版本
-
另外,您可能想考虑除
<marquee>之外的另一个选项,它是非标准的,不建议按照MDN 使用
标签: javascript html internet-explorer local-storage