Skip to content

Instantly share code, notes, and snippets.

@sanusart
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save sanusart/b4875eb264e46a0e789b to your computer and use it in GitHub Desktop.

Select an option

Save sanusart/b4875eb264e46a0e789b to your computer and use it in GitHub Desktop.
Redirect to mobile #mobile #javascript
<script type="text/javascript">
if ( window.sessionStorage.getItem('mob') !== 'no' ) {
if ((navigator.userAgent.match(/iPhone|Android|iPod|Opera Mobi|Opera Mini|BlackBerry|Nokia|SymbianOS|Windows CE|BenQ/i))) {
window.sessionStorage.setItem('mob','no');
var url = window.location.href;
var paramPos = url.indexOf("?");
location.replace("http://domain.com/m-site/" + ( paramPos != -1 ? "?" + url.substr(paramPos + 1) : "" ));
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment