.split() not working as expected in IE8

后端 未结 5 821
Happy的楠姐
Happy的楠姐 2021-01-13 03:48

I\'m using the following to extract variables from a URL contained in a variable. It works fine in modern browsers but in IE8 it fails on the first variable but succeeds on

5条回答
  •  猫巷女王i
    2021-01-13 04:50

    There have been some valid responses, but you may be interested in a function I use to retrieve GET parameters from URLs.

    var get = function (name, url) { // Retrieves a specified HTTP GET parameter. Returns null if not found.
        url = (typeof (url) === "undefined" ? window.location.href : url);
    
        var regex = new RegExp("[?&]" + name + "=([^&#]*)");
        var results = regex.exec(url);
        var output = (results ? results[1] : null);
    
        return output;
    };
    

    You could use it like this.

    var url = 'http://sagensundesign.com?height=400&width=300';
    
    var h = get("height",url);
    var w = get("width",url);
    

提交回复
热议问题