简体   繁体   中英

Redirecting automatically to another site in javascript

I have a website, with both mobile and desktop versions. But I would like to somehow connect them where the desktop site is the default landing page. So, if the viewport's width is smaller than 600px (for example), it automatically redirects to the mobile site (that is uploaded with a different domain). I am using React, so solutions using react would work as well. Does anyone know how to do this?

// use this to avoid redirects when a user clicks "back" in their browser
window.location.replace('http://somewhereelse.com');

// use this to redirect, a back button call will trigger the redirection again
window.location.href = "http://somewhereelse.com";

Already answered by Owen in this Question: What's the best way to automatically redirect someone to another webpage?

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