jquery 自定义插件



;(function( $ ){
	
	$.baiduDemo={
		random : function () {
			var tmp=Math.random()*10000;
			return tmp;
		},
		getCtx : function () {
			var obj=$("meta[name='company']");
			var content=obj.attr("content");
			if(!content || content==undefined || content=="" ){
				console.error("getCtx() company is null. company="+company);
			}
			return content;
		},
		toRedirectURL : function () {
			var ss=this.random();
			var url=$.baiduDemo.getCtx() +"/link/toRedirect.htm?pp="+ss;
			return url;
		},
		toMobileUI : function () {
			var ss=this.random();
			var url=$.baiduDemo.getCtx() +"/user/uMobileUI.htm";
			return url;
		},
		indexURL : function () {
			var ss=this.random();
			var url=$.baiduDemo.getCtx() +"/index.htm?pp="+ss;
			return url;
		},
		indexeErrorURL : function () {
			var errormsg="#stopback";
			var url=$.baiduDemo.indexURL()+errormsg;
			return url;
		},
		webStopBackOnThisUI : function () {

			var indexurl=document.location.href;
			var _indexurl_1="";
			var _indexurl_2="";

			var errormsg="#errormsg";
			var num=indexurl.indexOf(errormsg);

			if(num==-1){
				_indexurl_1=indexurl;
				_indexurl_2=indexurl+errormsg;
			}else{
				_indexurl_1=indexurl.substring(0,num);
				_indexurl_2=_indexurl_1+errormsg;
			}

			console.log("_indexurl_1 = "+_indexurl_1);
			console.log("_indexurl_2 = "+_indexurl_2);

			history.replaceState({goo:"stopback"},document.title,_indexurl_1);  	
			history.pushState({goo:""},document.title,_indexurl_2);

			window.addEventListener("popstate", function(e){  
			    var state=history.state;
			    var is_stopback=(state && state.goo=="stopback");
			    console.log("state = "+state+" , is_stopback= "+is_stopback);
			    if(is_stopback){
				   location.href=_indexurl_1;
			    }
			});
			
		},
		webStopBack : function () {
			history.replaceState({goo:"stopback"},document.title,$.baiduDemo.indexURL());  	
			history.pushState({goo:""},document.title,$.baiduDemo.indexeErrorURL());
			window.addEventListener("popstate", function(e){  
				var state=history.state;
				var is_stopback=(state && state.goo=="stopback");
				console.log("state = "+state+" , is_stopback= "+is_stopback);
				if(is_stopback){
					location.href=$.baiduDemo.indexURL();
				}
			});
		},
		webStopBackIndex : function () {
			
			var state=history.state;
			var is_stopback_1=(state && state.goo=="stopback");
			console.log("is_stopback_1 = "+is_stopback_1);

			if(is_stopback_1){
				history.replaceState({goo:"stopback"},document.title,$.baiduDemo.indexURL());
				history.pushState({goo:""},document.title,$.baiduDemo.indexeErrorURL());
			}
			window.addEventListener("popstate", function(e){
				var state=history.state;
				var is_stopback=(state && state.goo=="stopback");
				console.log("state = "+state+" , is_stopback= "+is_stopback);
				if(is_stopback){
					location.href=$.baiduDemo.indexURL();
				}
			});
			
		}
	};
})( jQuery );


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值