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

  • 8bitdigitaltv

    8bitdigitalt

    31 AĞUSTOS 2011
  • amc

    amc

    21 EYLÜL 2005
  • mliskIT

    mliskIT

    29 Mart 2012