/ Published in: JavaScript
URL: http://warpspire.com/posts/url-design/
/* * There’s a lot of awesome functionality built into linking elements like and . * If you middle click or command-click on them they’ll open in new windows. * When you hover over an your browser tells you the URL in the status bar. * Don’t break this behavior when playing with onReplaceState and onPushState. * Embed the location of AJAX requests in the href attributes of anchor elements. * Return true from Javascript click handlers when people middle or command click. * * http://warpspire.com/posts/url-design/ */
Expand |
Embed | Plain Text
$('a.ajaxylink').click(function(e){ // Fallback for browser that don't support the history API if (!('replaceState' in window.history)) return true // Ensure middle, control and command clicks act normally if (e.which == 2 || e.metaKey || e.ctrlKey){ return true } // Do something awesome, then change the URL window.history.replaceState(null, "New Title", '/some/cool/url') return false })
You need to login to post a comment.
