第一次加載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