简体   繁体   中英

Redirecting page mobile not working with javascript

I have been having problems with a web page and the way the content has been displaying on mobile. To get around this issue I thought it might be better if I direct to another page using javascript. Now there are two html pages, index.html and mobile.html. I have a script tag at the bottom of the index file checking if the screen width is less then 1000px if so do this:

<script> 
    if (screen.width <= 1000) {
        window.location.replace = "http://pmoney2.s3-website.eu-west-2.amazonaws.com/mobile.html";
    }
</script>

replace is an function you have to call it.

But you are assign it value instead of passing as argument. Do it like this :-

<script> 
    if (screen.width <= 1000) {
        window.location.replace("http://pmoney2.s3-website.eu-west-2.amazonaws.com/mobile.html");
    }
</script>

Or you can use href

<script> 
    if (screen.width <= 1000) {
        window.location.href = "http://pmoney2.s3-website.eu-west-2.amazonaws.com/mobile.html";
    }
</script>

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