jQuery.mobile.path.isSameDomain()

Utility method for determining if a URL has the same domain.

Utility method for determining if two different URLs share the same domain. This function returns a boolean true if the domain is the same, false if not.

absUrl1
absUrl2
Examples:

Various uses of jQuery.mobile.path.isSameDomain

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery.mobile.path.isSameDomain demo</title>
  <link rel="stylesheet" href="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
  <script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
  <script src="//code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
  <style>
  .versus {
    display: inline-block;
  }
  .compare {
    margin-bottom: 2.3em;
  }
  #myResult{
    border: 1px solid;
    border-color: #108040;
    padding: 10px;
  }
  </style>
</head>
<body>
 
  <div role="main" class="ui-content ui-mini">
    <div>
      <a href="javascript:void(0)" class="ui-btn ui-corner-all ui-btn-inline ui-shadow compare">Same Domain?</a>
      <div class="versus">
        <pre><code>http://example.com/</code></pre>
        <pre><code>http://slashdot.org/</code></pre>
      </div>
    </div>
    <div>
      <a href="javascript:void(0)" class="ui-btn ui-corner-all ui-btn-inline ui-shadow compare">Same Domain?</a>
      <div class="versus">
        <pre><code>http://edition.cnn.com/</code></pre>
        <pre><code>http://cnn.com/</code></pre>
      </div>
    </div>
    <div>
      <a href="javascript:void(0)" class="ui-btn ui-corner-all ui-btn-inline ui-shadow compare">Same Domain?</a>
      <div class="versus">
        <pre><code>http://www.amazon.co.uk/</code></pre>
        <pre><code>http://www.amazon.co.uk/</code></pre>
      </div>
    </div>
    <div id="myResult"></div>
  </div>
 
<script>
  $(document).ready(function() {
    $( ".compare" ).on( "click", function() {
      var urlContainers = $( this ).siblings( ".versus" ).find( "code" ),
        url1 = urlContainers.first().text(),
        url2 = urlContainers.last().text();
 
      $( "#myResult" ).text( String( $.mobile.path.isSameDomain( url1, url2 ) ) );
    })
  });
</script>
 
</body>
</html>
doc_jQuery
2016-03-28 15:04:49
Comments
Leave a Comment

Please login to continue.