PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 26, 2022

[FIXED] How to auto re-direct from other url?

 July 26, 2022     css, dreamweaver, html, javascript, url-redirection     No comments   

Issue

I'm writing for a condizionale auto re-direct url, but it doesn't works. I tried with two methods:

<script>
      function mobileDevice()
        {
        $type = $_SERVER[‘HTTP_USER_AGENT’];
        if(strpos((string)$type, “Windows Phone”) != false || strpos((string)$type, “iPhone”) != false || strpos((string)$type, “Android”) != false)
        return true;
        else
        return false;
        }
        if(mobileDevice() == true)
        header(‘Location: https://www.organization.org/mobile/index_mobile.htm‘);
</script>

and

<script type="text/javascript">
      if (screen.width <= 414) {
        document.location = "index.htm";
        <script language=javascript>
    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
       location.replace("https://www.organization.org/mobile/index_mobile.htm");
    }
          </script>
      }
    </script>

As I yet announced, no one of this works, why?


Solution

In plain Javascript you should assign the value location instead of using method to redirect. replace method won't save in history the change of url.

window.location = "https://www.organization.org/mobile/index_mobile.htm";

Also you are nesting two tags in your second approach. The correct code would be:

<script type="text/javascript">
      if (screen.width <= 414) {
        document.location = "index.htm";
        if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
          location.replace("https://www.organization.org/mobile/index_mobile.htm");
        }
      }
</script>


Answered By - jmtalarn
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing