導航:首頁 > 編程語言 > js判斷用戶行為

js判斷用戶行為

發布時間:2024-04-02 21:01:42

① 通過js判斷當前訪問的是電腦還是手機

<scripttype="text/javascript">
varbForcepc
=fGetQuery("dv")=="pc";
function
fBrowserRedirect(){
varsUserAgent=navigator.userAgent.toLowerCase();
varbIsIpad=sUserAgent.match(/ipad/i)==
"ipad";
varbIsiphoneOs=sUserAgent.match(/iphoneos/i)=="iphoneos";
varbIsMidp=sUserAgent.match(/midp/i)=="midp";
varbIsUc7=sUserAgent.match(/rv:1.2.3.4/i)=="rv:1.2.3.4";
varbIsUc=sUserAgent.match(/ucweb/i)=="ucweb";
varbIsAndroid=sUserAgent.match(/android/i)=="android";
varbIsCE=sUserAgent.match(/windowsce/i)=="windowsce";
varbIsWM=sUserAgent.match(/windowsmobile/i)=="windows
mobile";
if(bIsIpad){
varsUrl=
location.href;
if(!bForcepc){
window.location.href="http://ipad.mail.163.com/";
}
}
if(bIsIphoneOs||bIsAndroid){
varsUrl=
location.href;
if(!bForcepc){
window.location.href="http://smart.mail.163.com/";
}
}
if(bIsMidp||bIsUc7||bIsUc||bIsCE||bIsWM){
varsUrl=
location.href;
if(!bForcepc){
window.location.href="http://m.mail.163.com/";
}
}
}
function
fGetQuery(name){//獲取參數值
varsUrl=window.location.search.substr(1);
varr=sUrl.match(newRegExp("(^|&)"+name+
"=([^&]*)(&|$)"));
return(r==null?null:(r[2]));
}
function
fShowVerBlock(){
if(bForcepc){
document.getElementByIdx_x("dv_block").style.display="block";
}
else{
document.getElementByIdx_x("ad_block").style.display="block";
}
}
fBrowserRedirect();
</script>

這只是弱判斷,用戶通過F12或者瀏覽器設置是可以改的,並不能代表用戶真實情況

② JS判斷用戶是否登陸登陸

我認為你是想用AJAX來實現,
var i=1;

function listNews(user,password)
{

var xmlHttp1 = null;
requestNewsNum=requestNum;

var keyword = escape(escape(n_keyword));
var str = "'"+user+"','"+password+"'";
i = requestNum;
switch(requestNum){
case 1:
startRequest("需要調用方法的路徑和名字"+str,1);
break;

}
}
function createXMLHttpRequest(i) {
if(window.XMLHttpRequest) {
eval( 'xmlHttp'+i+"=new XMLHttpRequest()");
}else if(window.ActiveXObject) {
eval( 'xmlHttp'+i+"=new ActiveXObject('Microsoft.XMLHTTP')");
}
}

function startRequest(url,i) {
createXMLHttpRequest(i);
eval( "("+'xmlHttp'+i+")"+".onreadystatechange = "+function(){
if(eval( "("+'xmlHttp'+i+")"+".readyState==4")){
if(eval( "("+'xmlHttp'+i+")"+".status==200")) {
document.getElementById("DIV的名字(顯示的地方)"+i).innerHTML = eval( "("+'xmlHttp'+i+")"+".responseText");
}
}
});
eval( "("+'xmlHttp'+i+")"+".open('GET',url,true)");
eval( "("+'xmlHttp'+i+")"+".send(null)");
}
這是整個AJAX的框架.

③ nodejs判斷用戶是否有許可權訪問某個頁面

功能 :判斷當前用戶是否有許可權訪問當頁面
思路:讀取當前用戶的許可權(在登陸驗證是設置的)
和標簽在jsp頁面取到的值進行比較,不匹配時跳轉到指定頁面
總結:標簽類一般存放在web-inf/lib
xxxx.tld 配置 標簽類的參數定義和指定類名
web-inf.xml 指定xxxx.tld的位置和定義名字
<mytag:CheckPower power="manager" gotoPage="login.jsp"/>
錯誤總結:寫標簽類的時候get/set方法漏了 ,報錯。
寫jsp頁面時ctrl c ctrl v時 uri沒改,頁面不認。

④ 前端js 怎麼判斷用戶是否安裝了某APP,安裝了不直接打開這個應用而是進行其他操作

判斷當前頁面是否在app內部打開,單純的web前端還不能解決
需要客戶端對userAgent添加自己app相關的欄位
(useragent設置Android:http://www.jincon.com/archives/354/)
(useragent設置IOS:http://www.jianshu.com/p/5f02451b8e87)
var userAgent = navigator.userAgent.toLowerCase(), //獲取userAgent
isInapp = userAgent.indexOf("sunyuki")>=0;//查詢是否有相關app的相關欄位
希望對你有幫助!

⑤ js如何判斷用戶行為動態添加input屬性

<inputtype="text">
<script>
document.querySelector('input[type="text"]').oninput=function(e){
constvalue=e.target.value;
if(value.trim()){
e.target.setAttribute('linyu','active');
}else{
e.target.removeAttribute('linyu');
}
}
</script>

通過 input 事件來實現。輸入框更改的時候觸發。

⑥ js 判斷是否登錄

如果一定要用js驗證是否登錄,那麼,就需要使用cookie記錄登錄狀態,js可以讀取進行判斷。

//JS操作cookies方法!
//寫cookies
functionsetCookie(name,value)
{
varDays=30;
varexp=newDate();
exp.setTime(exp.getTime()+Days*24*60*60*1000);
document.cookie=name+"="+escape(value)+";expires="+exp.toGMTString();
}
//讀取cookies
functiongetCookie(name)
{
vararr,reg=newRegExp("(^|)"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg))returnunescape(arr[2]);
elsereturnnull;
}
//刪除cookies
functiondelCookie(name)
{
varexp=newDate();
exp.setTime(exp.getTime()-1);
varcval=getCookie(name);
if(cval!=null)document.cookie=name+"="+cval+";expires="+exp.toGMTString();
}
//使用示例
setCookie("name","hayden");
alert(getCookie("name"));
閱讀全文

與js判斷用戶行為相關的資料

熱點內容
win10快速訪問共享文件 瀏覽:259
喜馬拉雅電腦文件導出 瀏覽:615
js取商運算 瀏覽:719
幼兒編程貓是什麼 瀏覽:347
dnf哪個網站補丁 瀏覽:646
iphone自動關機能打通 瀏覽:794
怎麼連接伺服器資料庫 瀏覽:907
大數據時代羅輯思維 瀏覽:827
聯想y50pwin10開機速度 瀏覽:236
網路游戲對我們的身體有什麼壞處 瀏覽:950
電腦接觸不良文件 瀏覽:689
星成大海是哪個app可以看 瀏覽:418
施耐德plc編程軟體哪個好用 瀏覽:680
網路k歌什麼麥 瀏覽:653
java創建oracle存儲過程 瀏覽:84
iphone6越獄後不保修 瀏覽:302
app君生病了 瀏覽:256
抖音大數據處理中心在哪裡 瀏覽:668
5s的app在那裡 瀏覽:665
ssojava 瀏覽:282

友情鏈接