简体   繁体   中英

html/code - Divert to desktop/mobile site on enter the site

I'm working on a site with separate pages for mobile and desktop. I have a code that diverts people to mobile or desktop based on screen resolution.

I want to change this so the code only runs On Domain/Website Load - for example: IfPreviousDomain != this Domain run code.... (www.example.com)

The code we have now looks like this:

<script> if ( (screen.width < 1024) && (screen.height < 768) ) { 
window.location = 'http://www.example.com/Mobile.html';
}  </script>

OR

<script> if ( (screen.width > 1024) && (screen.height > 768) ) { 
window.location = 'http://www.example.com/';
}  </script>

if there is better code for the job please let me know. Also I only know basic html and Python so I don't even know what language the above code is.

The language above is JavaScript. I don't see any better option than the version above. If you wrap your code with

document.addEventListener("DOMContentLoaded", function(event) { 
  //here goes your code
});

then the function should only be executed on the initial load.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM