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

  • Break

    Break

    10 Aralık 2005
  • CZTUTORIALS

    CZTUTORIALS

    28 Ocak 2011
  • Sean Murphy

    Sean Murphy

    4 ŞUBAT 2009