javascript - 用于在表单提交上设置 cookie 的 JS 适用于 Firefox,但不适用于 Edge/Chrome
问题描述
我有一个引导模式,当页面加载要求用户设置他们的位置并将这个值保存到 cookie 时会弹出。
这一切在 Firefox 中运行良好,但在 Edge 或 Chrome 中不起作用。有人有想法么?
<script>
function setCookie(cookieName, cookieValue, nDays) {
var today = new Date();
var expire = new Date();
if (!nDays)
nDays=1;
expire.setTime(today.getTime() + 3600000*24*nDays);
document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
return false
}
</script>
<div class="modal_container">
<!-- Modal -->
<div class="modal fade" id="store_prompt" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Location Number</h5>
</div>
<div class="modal-body">
<form onsubmit="javascript:return setCookie('location', this.querySelector('select').value, 365);">
<div class="form-group">
<label for="LocationSelect">Please select your location below.</label>
<select class="form-control" id="LocationSelect">
<option value='1' >1 - Location A</option>
<option value='2' >2 - Location B</option>
</select>
</div>
<button type="submit" class="btn btn-primary btn-lg btn-block" onclick="closemodal(); location.reload();">Save changes</button>
</form>
</div>
</div>
</div>
</div>
解决方案
推荐阅读
- android - 找不到默认活动android studio?
- javascript - 未选择 SVG 元素 - 条形图未显示
- sql - 通过从另一个表中获取数据来更新列
- javascript - javascript中的Jquery .not()等价物
- amazon-web-services - 奇怪的 Ignite Client 行为;ELB 发现失败,客户端扫描子网并加入另一个服务器集群
- java - 是否可以在注释中有条件地应用注释?
- scala - typedLit 列的总和计算结果为 NULL
- unity3d - 如何在运行时保存修改后的网格?
- r - 如何在 JSON 对象中循环遍历 JSON 数组
- arduino - 让 Arduino GSM 库与 Nucleo L073RZ 一起使用时出现问题