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

  • DigitalRev TV

    DigitalRev T

    30 AĞUSTOS 2007
  • jesiel santos

    jesiel santo

    15 Ocak 2009
  • wowchick16

    wowchick16

    17 Mart 2007