zoukankan      html  css  js  c++  java
  • 【js】判断设备类型,访问相应的网站

    引入

    function uaredirect(f) {
    	try {
    		if (document.getElementById("bdmark") != null) {
    			return
    		}
    		var b = false;
    		if (arguments[1]) {
    			var e = window.location.host;
    			var a = window.location.href;
    			if (isSubdomain(arguments[1], e) == 1) {
    				f = f + "/#m/" + a;
    				b = true
    			} else {
    				if (isSubdomain(arguments[1], e) == 2) {
    					f = f + "/#m/" + a;
    					b = true
    				} else {
    					f = a;
    					b = false
    				}
    			}
    		} else {
    			b = true
    		}
    		if (b) {
    			var c = window.location.hash;
    			if (!c.match("fromapp")) {
    				if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i))) {
    					location.replace(f)
    				}
    			}
    		}
    	} catch (d) {}
    }
    
    function isSubdomain(c, d) {
    	this.getdomain = function(f) {
    		var e = f.indexOf("://");
    		if (e > 0) {
    			var h = f.substr(e + 3)
    		} else {
    			var h = f
    		}
    		var g = /^www./;
    		if (g.test(h)) {
    			h = h.substr(4)
    		}
    		return h
    	};
    	if (c == d) {
    		return 1
    	} else {
    		var c = this.getdomain(c);
    		var b = this.getdomain(d);
    		if (c == b) {
    			return 1
    		} else {
    			c = c.replace(".", "\.");
    			var a = new RegExp("\." + c + "$");
    			if (b.match(a)) {
    				return 2
    			} else {
    				return 0
    			}
    		}
    	}
    };
    

    页面使用

    <script src="~/js/uaredirect.js"></script>
    <script >uaredirect("需要跳转的url")</script>
    

      

  • 相关阅读:
    你人生中的那口井挖了没有?
    Stream接口
    console (控制台)
    assert.fail()
    assert.strictEqual()
    assert.equal()
    assert.ifError()
    assert.ok()
    nodejs assert 模块
    闭包
  • 原文地址:https://www.cnblogs.com/bestsamcn/p/4981245.html
Copyright © 2011-2022 走看看