Created
April 15, 2014 05:36
-
-
Save benwong/10704873 to your computer and use it in GitHub Desktop.
Domain Specific Content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Domain Specific Content</title> | |
<style>.domain-specific {display: none;}</style> | |
</head> | |
<body> | |
<div class="domain-specific" data-domains="['www.mydomain.com']"> | |
<p>To go places and do things that have never been done before – that’s what living is all about.</p> | |
</div> | |
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> | |
<script> | |
(function($, window){ | |
"use strict"; | |
var $ds = $('.domain-specific'); | |
$ds.each(function(index, e){ | |
var domains = eval($(this).attr('data-domains')), | |
hasMatch = false, | |
i = 0; | |
while (!hasMatch && i < domains.length) { | |
var re = new RegExp(domains[i]); | |
if (re.test(window.location.hostname)) { | |
hasMatch = true; | |
} | |
i++; | |
} | |
if (hasMatch) { | |
$(this).show(); | |
} | |
else { | |
$(this).hide(); | |
} | |
}); | |
}(jQuery, window)); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment