第一次加载html,它显示文本为是,第二次当从缓存中重新加载或加载它应该显示一些其他文本编号。Html页面上重新加载不同的html
回答
您可以使用cookie来识别回访者:
<html>
<body>
<script language="javascript">
// sets a cookie with a certain name, value and optional expiration in days
function setCookie(c_name, value, exdays) {
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
// retrieves the value of a cookie of a certain name (or returns undefined)
function getCookie(c_name) {
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++) {
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name) return unescape(y);
}
}
// if the cookie was set, then the user has been here already
if (getCookie("visited") == "true") {
document.write("NO");
} else {
// otherwise, set the cookie and assume the user has not been here before
setCookie("visited", "true");
document.write("YES");
}
</script>
</body>
</html>
这个需求是我第一次在提交html1之后得到一个html/jsp的html1,它在iOS移动设备上安装了一个配置文件,并且在完成安装后,当你点击它时,它会打开一个浏览器这次我上次访问过的相同的html1,我希望它重定向到一个不同的URL。目前我找到相同的html1页面,我不知道如何重新定向它新的URL当它回来.. – karpra 2012-07-20 21:36:47
感谢您的这种做法,但我想控制代码不是基于cookie,但会议上我有一个代码如果我错了,请更正代码片段.. out.println(“”我想检查一个脚本的条件让标签,并显示基于会话的HTML .. – karpra 2012-07-22 01:54:56
这里是我试过out.println代码片段( \t \t \t \t \t \t \t “” + \t \t \t \t \t \t \t \t \t“
当你使用jQuery,它似乎最容易使用的jQuery Cookie plugin:
// assigns the value returned by the cookie to the variable,
// if no cookie, or no value, is returned, the string is assigned instead.
var cookieValue = $.cookie('firstVisit') || 'Yes';
// if there's no cookie, then a cookie is set.
if (!$.cookie('firstVisit')) {
$.cookie('firstVisit', 'No', {
expires: 7 // expires in 7 days, adjust to taste.
});
}
$('#firstVisit').text(cookieValue);
上面的代码更新为一个小整洁,和更少的重复:
// if the cookie is not set, the cookieVal variable is falsey
var cookieVal = $.cookie('firstVisit'),
// creating a reference to the relevant div
div = $('#firstVisit');
// if the cookieVal evaluates to false the cookie is set,
// and the text of the div is 'Yes'
if (!cookieVal) {
$.cookie('firstVisit', 'No');
div.text('Yes');
}
// otherwise...
else {
// text of the div is equal to the value returned from the cookie
div.text(cookieVal);
}
+1 yep,就像那样 – 2012-07-20 22:16:44
- 1. 弹出html页面重新加载滞后的父页面
- 2. 使用html锚点(#)强制页面重新加载 - HTML&JS
- 3. 页面加载HTML页面的不同内容
- 4. 在一个html页面中加载不同的页面?
- 5. 使用HTML5 Websockts在主HTML页面中加载不同的HTML页面
- 6. HTML:更改网址而不重新加载页面?
- 7. HTML - 更新\更新页面内容,无需刷新\重新加载页面
- 8. 表值不上重新加载页面
- 9. HTML页面重载自动
- 10. HTML按钮,重新加载引用页
- 11. 用新标题重新加载html页面
- 12. 刮几秒后重新加载页面的网站的HTML
- 13. 如何停止PhoneGap中的重新加载页面(HTML)导航到上一页?
- 14. 重新排列HTML页面
- 15. 在html页面上加载WordPress帖子
- 16. html/javascript代码加载html页面
- 17. html页面加载消息
- 18. jquery ajax重新加载整个页面的html
- 19. 强制重新加载一小段时间后的html页面
- 20. html页面上的不同XML数据
- 21. jsp页面未从html页面加载
- 22. 将HTML或jade页面加载到HTML或jade页面的div
- 23. 在html更改上重新加载javascript
- 24. 地图不加载到HTML页面
- 25. JavaScript函数不会加载html页面
- 26. 重新加载html元素
- 27. 重新加载按钮上的页面
- 28. 如何重新加载HTML页面部分
- 29. 如何设置webpack观看并重新加载HTML页面?
- 30. 重新加载一个静态HTML页面,但扩大了URL
好的,你需要问一个具体的问题,这样我们就知道我们正在回答什么(以及你的期望)。另外,如果你能证明你已经尝试过某些东西,你是否遇到了一个特殊的问题,这会有所帮助? – 2012-07-20 21:10:17
@ karpra-你能否在这里澄清一下问题?我假设你的意思是:“_是否有一种方法可以在第一次加载页面时在文本中显示'是',但是当页面再次加载或从缓存加载时显示'否'?” – s0d4pop 2012-07-20 21:11:13
设置cookie,尝试jquery cookie – 2012-07-20 21:16:52