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

  • Doug Bernards

    Doug Bernard

    7 Kasım 2007
  • Eric Enge

    Eric Enge

    2 Kasım 2009
  • pain975

    pain975

    27 NİSAN 2008