I´m using a modal to see my contact info in which there are 4 btn´s which doesn´t always work (Page=UNDEFINED). Can someone help me understand why? <pre><code>&lt;!--Kontakt modal--&gt; &lt;li&gt;&lt;a data-toggle="modal" href="#myModal"&gt;Kontakta mig&lt;/a&gt;&lt;/li&gt; &lt;div id="myModal" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt; &lt;div class="modal-dialog"&gt; &lt;div class="modal-content"&gt; &lt;div class="modal-header"&gt; &lt;!--Titeln i modal--&gt; &lt;h2 class="modal-title" id="myModalLabel"&gt;Kontakta mig&lt;/h2&gt; &lt;/div&gt; &lt;div class="modal-body"&gt; &lt;a class="btn btn-default table-responsive glyphicon glyphicon-map-marker" href="https://maps.google.com/maps?q=Moldegatan+1C%2c+Bor%C3%A5s%2c+Sweden&amp;hl=en&amp;ie=UTF8&amp;sll=38.882147%2c-76.99017&amp;sspn=0.014866%2c0.027874&amp;oq=Mo&amp;hnear=Moldegatan+1C%2c+504+32+Bor%C3%A5s%2c+Sweden&amp;t=m&amp;z=16&amp;source=gplus-ogsb" role="button"&gt;Moldegatan 1C 50432 BORÅS&lt;/a&gt; &lt;hr /&gt; &lt;a class="btn btn-default table-responsive glyphicon glyphicon-earphone" href="tel:+0735451624" role="button"&gt;Telefonnummer: 0735451624&lt;/a&gt; &lt;hr /&gt; &lt;a class="btn btn-default table-responsive glyphicon glyphicon-envelope" href="mailto:mr_clavijo@hotmail.com" role="button"&gt;E-mail: mr_clavijo@hotmail.com&lt;/a&gt; &lt;hr /&gt; &lt;div class="intent"&gt; &lt;img src="Content/Bilder/facebook.png" alt="Facebook" /&gt; &lt;a class="btn btn-default" href="http://facebook.com/carlos.clavijo.77" data-scheme="fb://profile/555447256"&gt;Facebook&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="modal-footer"&gt; &lt;div class="btn-group"&gt; &lt;button class="btn btn-danger" data-dismiss="modal"&gt;Stäng&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;!-- /modal-content --&gt; &lt;/div&gt; &lt;!-- /modal-dialog --&gt; &lt;/div&gt; &lt;!-- /myModal --&gt; </code></pre> <p>// JavaScript. I´m using this so that when using a smartphone or tablet it will open up the aplication istead of the explorer. I´m kind of new to this so please bare with me. </p> <p>When using this function and press one of the buttons in the kontakt modal it works sometimes, but sometimes it shows up as page undefined. What am I missing?</p> <pre><code>(function() { // tries to execute the uri:scheme function goToUri(uri, href) { var start, end, elapsed; // start a timer start = new Date().getTime(); // attempt to redirect to the uri:scheme // it'll stutter for a split second, causing the timer to be off document.location = uri; // end timer end = new Date().getTime(); elapsed = (end - start); // if there's no elapsed time, then the scheme didn't fire, and we head to the url. if (elapsed &lt; 1) { document.location = href; } } $('a.btn-default').on('click', function(event) { goToUri($(this).data('scheme'), $(this).attr('href')); event.preventDefault(); }); })(); </code></pre>