SORU
10 NİSAN 2009, Cuma


Nasıl hostname ve yol içine bir URL ayrıştırmak javascript mı?

Bir dize almak istiyorum

var a = "http://example.com/aa/bb/"

ve bir nesne gibi içine işlemek

a.hostname == "example.com"

ve

a.pathname == "/aa/bb"

CEVAP
10 NİSAN 2009, Cuma


var getLocation = function(href) {
    var l = document.createElement("a");
    l.href = href;
    return l;
};
var l = getLocation("http://example.com/path");
console.debug(l.hostname)
>> "example.com"
console.debug(l.pathname)
>> "/path"

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • 2ndfloor91

    2ndfloor91

    17 Kasım 2007
  • ElChakotay Andrich

    ElChakotay A

    10 EKİM 2013
  • Khan Academy

    Khan Academy

    17 Kasım 2006