Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// tries to execute the uri:scheme
function uriSchemeWithHyperlinkFallback(uri, href) {
if(!window.open(uri)){
window.location = href;
}
}
<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>
@ChaseFlorell

This comment has been minimized.

Copy link

ChaseFlorell commented Jan 16, 2014

Nice improvement. How is it working?

@andrepura

This comment has been minimized.

Copy link

andrepura commented Sep 19, 2014

i just tested it and it works great using android

@gianpaj

This comment has been minimized.

Copy link

gianpaj commented Mar 21, 2016

How do you for example make a facebook share?

@cropots

This comment has been minimized.

Copy link

cropots commented Dec 13, 2019

Not work for me on chrome android.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.