❶ js怎麼控制手機頁面防止刷新js怎麼控制手機頁面防止刷新
如何防止惡意頻繁刷新頁面?
停止頻繁刷新的方法:盡可能少的減少回發和請求的次數。具體事項:
1,盡可能少地使用伺服器端控制項,
2,習慣用javascript做一些室內操作不訪問伺服器,
3、利用ajax技術,
4.學習必要的js框架。
如何防止頁面刷新,後退導致的重復提交?
原理:用新頁面的URL替換當前的歷史紀錄,這樣瀏覽歷史記錄中就只有一個頁面,後退按鈕永遠失效。註:history.go和history.back(包括用戶按瀏覽器歷史前進後退按鈕)觸發,頁面由於使用pushState修改了history),會觸發popstate事件。【代碼如下】註:直接放在不想後退跳轉的頁面即可!方法一:scripttype="text/javascript">jQuery(document).ready(function($){if(window.historywindow.history.pushState){$(window).on('popstate',function(){window.history.forward(1);});}});/script>方法二【推薦】:$(function(){if(window.historywindow.history.pushState){$(window).on('popstate',function(){window.history.pushState('forward',null,'#');window.history.forward(1);});}window.history.pushState('forward',null,'#');//在IE中必須得有這兩行window.history.forward(1);})其中涉及到的方法詳細介紹:一、window.history:表示window對象的歷史記錄二、歷史記錄的前進和後退window.history.forward()---此方法載入歷史列表中的下一個URL,同瀏覽器中點擊向前按鈕;window.history.back()---此方法載入歷史列表中的前一個URL,同瀏覽器中點擊後退按鈕。可移動到指定歷史記錄點:通過指定一個相對於當前頁面位置的數值,你可以使用go()方法從當前會話的歷史記錄中載入頁面(當前頁面位置索引值為0,上一頁就是-1,下一頁為1)如:要後退一頁(相當於調用back()):window.history.go(-1);向前移動一頁(相當於調用forward()):window.history.go(1);window.history.length:可以查看length屬性值,可知道歷史記錄棧中共有多少個記錄點。三、操作歷史記錄點HTML5的新API擴展了window.history,可實現存儲、替換當前歷史記錄點,以及監聽歷史記錄點。1、存儲、替換當前歷史記錄點創建當前歷史記錄點pushState(state,title,url):創建(添加)一個新的history實體,state:狀態對象,記錄歷史記錄點的額外對象(要跳轉的URL),可以為空;title:頁面標題,目前所有瀏覽器都不支持;url:可選的url,瀏覽器不會檢查url是否存在,只改變url,url必須同域。window.history.pushState(json,」",」404NotFound);替換當前歷史記錄點replaceState():修改當前的history實體,不會新增。類似replace(url),要更新當前歷史記錄的狀態對象或URL時,使用replaceState()方法會更合適。2、監聽歷史記錄點onpopstate()當history實體被改變時,popstate事件將會發生;onhashchange()可監聽URL的hash部分。3、讀取現有state當頁面載入時,它可能會有一個非空的state對象。當頁面重新載入,頁面將收到onload事件,但不會有popstate事件。然而,如果你讀取history.state屬性,將在popstate事件發生後得到這個state對象。
ASP.NET用JS如何關閉當前頁面刷新主頁面?
一個簡單的方法就是,首先在頁面上放置一個伺服器控制項Button,然後在這個Button的clientclick事件里用showModalDialog彈出窗口,當你把這個窗口關閉的時候,父窗口就自動刷新了,
5?JS怎麼實現頁面定時刷新?
可以通過js去控制讓頁面每隔多長時間刷新一次rscript>//這是一段jquery代碼,需要先載入jquery$(function(){ //頁面載入完後30秒刷新當前頁面 setTimeout(function(){window.location.reload()},30000);})/script>r
❷ js中網頁前進和後退的代碼
前進: history.forward();=history.go(1);
後退: history.back();=history.go(-1);
注意事項:前進後退按鈕是需要在特定環境下才有效果的,即你需要從另一個頁面進入到這個頁面後,點擊這個後退按鈕才有後退的效果,否則是沒有的。
【拓展資料】
javascript中的後退和刷新;
<input type=button value=刷新 onclick="window.location.reload()">
<input type=button value=前進 onclick="window.history.go(1)">
<input type=button value=後退 onclick="window.history.go(-1)">
<input type=button value=前進 onclick="window.history.forward()">
<input type=button value=後退 onclick="window.history.back()"> 後退+刷新<input type=button value=後退 onclick="window.history.go(-1);window.location.reload()">在C# Web程序中,如為頁面按鈕寫返回上一頁代碼
this.RegisterClientScriptBlock("E", "<script language=javascript>history.go(-2);</script>");
其中,history.go(-2),要寫為-2,因在按鈕事件觸發前,已刷新一次頁面,所以應是-2。
Response.Write("<script language=javascript>history.go(-2);</script>");
此處也要寫為「-2」。跟直接寫腳本的有所不同。history.back()是會上一頁
i=1
history.go(i)去指定的某頁
如果是history.go(0)那就是刷新這兩個屬於JS代碼,相當於IE的前進、後退功能。
具體的用處就要看什麼時候需要這個就用上。比如用戶注冊時的驗證是後台驗證,不符合要求的時候就可以用這個,可以最大限度保證用戶少重復輸入數據。
例如:載入頁面:
function onLoadPage(){
if(event.srcElement.tagName=="SPAN"){
oFrame=top.window.middle.frames[2];
oTxt=event.srcElement.innerText;
switch(oTxt){
case "前 進":
oFrame.history.go(1);
case "後 退":
oFrame.history.back();
case "刷 新":
oFrame.location.reload();
}
}
}
打開一個jsp頁面,肯定是用客戶端腳本進行刷新了。
Javascript刷新頁面的幾種方法:
1 history.go(0)
2 location.reload()
3 location=location
4 location.assign(location)
5 document.execCommand('Refresh')
6 window.navigate(location)
7 location.replace(location)
8 document.URL=location.href
❸ 用js如何控制 html5 video的快進後退。不要第三方插件。繼續代碼。
代碼如下:
<scripttype="text/javascript">functionvidplay() {varvideo=
document.getElementById("Video1");varbutton =
document.getElementById("play");if(video.paused) {
video.play();
button.textContent ="||";
}else{
video.pause();
button.textContent =">"
}
}functionrestart() {varvideo = document.getElementById("Video1");
video.currentTime = 0;
}functionskip(value) {varvideo = document.getElementById("Video1");
video.currentTime += value;
}</script></head><body><videoid="Video1">// Replace these with your own video files.<sourcesrc="demo.mp4"type="video/mp4"/>
<sourcesrc="demo.ogv"type="video/ogg"/>HTML5 Video is required for this example.<ahref="demo.mp4">Download the video</a>file.</video><divid="buttonbar">
<buttonid="restart"onclick="restart();">[]</button><buttonid="rew"onclick="skip(-10)"><<</button><buttonid="play"onclick="vidplay()">></button>
<buttonid="fastFwd"onclick="skip(10)">>></button></div>
注意事項
一、history.pushState(data, title [, url])
往歷史記錄堆棧頂部添加一條記錄;
data: onpopstate事件觸發時作為參數傳遞過去;
title:頁面標題,當前所有瀏覽器都會忽略此參數;
url: 頁面地址,可選,預設為當前頁地址;
二、history.replaceState(data, title [, url])
更改當前的歷史記錄,參數同上;
三、history.state:
用於存儲以上方法的data數據,不同瀏覽器的讀寫許可權不一樣;
四、window.onpopstate:響應pushState或replaceState的調用;
HTML實現 後退【window.history.back()】默認
HTML實現 後退【window.history.back(-1)】 括弧裡面的負數字代表後退幾個頁面,如果是-2的話就代表後退2頁
HTML實現 前進【window.history.forward()】//不常用
HTML實現 前進【window.history.forward(1)】//不常用 括弧裡面的正數就代表要前進的頁。如果是3就表示前進3頁
[html] view plain
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<p>這是第一個頁面</p>
<a href="HTMLPage2.htm">到dom頁</a>
<input type="button" onclick="javascript:window.history.back()" value="後退"/>
<input type="button" onclick="javascript:window.history.forward()" value="前進" />
</body>
</html>
[html] view plain
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<p>這是第二個頁面</p>
<a href="HTMLPage3.htm">轉到第一頁</a>
<a href="javascript:window.history.back()">後退</a>
<a href="javascript:window.history.forward()">前進</a>
</body>
</html>
❹ 後退一頁連接代碼 JS 或者VBS
1. Javascript 返回上一頁 history.go(-1), 返回兩個頁面: history.go(-2);
2. history.back().
3. window.history.forward()返回下一頁
4. window.history.go(返回第幾頁,也可以使用訪問過的URL)
例:
<a href="javascript:history.go(-1);">向上一頁</a>
response.Write("<script language=javascript>")
response.Write("if(!confirm('完成任務?')){history.back();}")
response.Write("</script>")
response.Write("<script language=javascript>history.go(-1);</script>")
<a href="javascript:history.go(-1);">向上一頁</a>
頁面跳轉:onclick="window.location.href='list.aspx'"
❺ JS 後退 history.go(-1) 不回到指定頁面
這個需要你做url 重定向
網路一下吧 ,大概思路就是登錄時帶著之前訪問的urlA
登錄成功之後頁面重新定向到urlA。