Forked from kmallea/uriSchemeWithHyperlinkFallback.js
Created
March 16, 2022 09:07
-
-
Save Metacowboy/be4e72e631656ed652eb615b73f67f43 to your computer and use it in GitHub Desktop.
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
// tries to execute the uri:scheme | |
function uriSchemeWithHyperlinkFallback(uri, href) { | |
if(!window.open(uri)){ | |
window.location = href; | |
} | |
} |
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
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> | |
<script src="uriSchemeWithHyperlinkFallback.min.js"></script> | |
</head> | |
<body> | |
<!-- links will work as expected where javascript is disabled--> | |
<a class="intent" | |
href="http://facebook.com/someProfile" | |
data-scheme="fb://profile/10000">facebook</a> | |
<script> | |
// `intent` is the class we're using to wire this up. Use whatever you like. | |
$('a.intent').on('click', function (event) { | |
uriSchemeWithHyperlinkFallback($(this).data('scheme'), $(this).attr('href')); | |
// we don't want the default browser behavior kicking in and screwing everything up. | |
event.preventDefault(); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment