jQuery.mobile.path.isSameDomain()


jQuery.mobile.path.isSameDomain( absUrl1, absUrl2 )Returns: Boolean

Description: 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.

Example:

Various uses of jQuery.mobile.path.isSameDomain

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!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.5.0-alpha.1/jquery.mobile-1.5.0-alpha.1.min.css">
<script src="//code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="//code.jquery.com/mobile/1.5.0-alpha.1/jquery.mobile-1.5.0-alpha.1.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-button ui-corner-all ui-button-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-button ui-corner-all ui-button-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-button ui-corner-all ui-button-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>

Demo: