muhraff / jQTips

jQuery tips & helps
0 stars 0 forks source link

Getting URL / hash location / substring / jQuery #4

Open muhraff opened 7 years ago

muhraff commented 7 years ago
var pathname = window.location.pathname; // Returns path only
var url      = window.location.href;     // Returns full URL
var hashPt = window.location.hash; // Returns hash path
var hashPt = window.location.hash.substring(1); // Returns removed  hash path

  //-----------------------
    // http://www.domain.com:8082/index.php#tab1?foo=789

    Property    Result
    ------------------------------------------
    host        www.domain.com:8082
    hostname    www.domain.com
    port        8082
    protocol    http:
    pathname    index.php
    href        http://www.domain.com:8082/index.php#tab1
    hash        #tab1
    search      ?foo=789

    var x = $(location).attr('<property>');