How To Auto Switch To Mobile Site |
Post Reply |
Author | |
insaneman12
Newbie Joined: Apr 17 2015 Location: Arizona Status: Offline Points: 42 |
Post Options
Thanks(0)
Posted: Apr 17 2015 at 8:11am |
Hey Everyone I just wanted to write this tutorial on how to have the website redirect to the mobile page automatically if someone is using a cell phone. I spent hours trying to figure this out and finally got it to work.
First - Build your main and mobile sites. I did it in the same file. Second - Open the source code. Should below the page tabs. Third - Add a New Codeblock. I named it Mobile, creative I know, name it what you want then type - javascript position - header Fourth - Type in or copy and paste: if (screen.width <= 800) { window.location = "mobile.htm"; } Choose the screen width you want. You can even change it to a range if you want. Change mobile.htm to what your mobile page name is. Fifth - Save the page and upload with complete selected in the middle What this does is find out the screen width in px, not the resolution but the size, <= smaller than or equil to 800px wide. window.location = "mobile.htm": sends the user to either the mobile or the destop sites based off the screen width. Hope this helps. |
|
Dmit OE
Admin Group Joined: May 31 2012 Status: Offline Points: 5283 |
Post Options
Thanks(1)
|
Hi, and thank you.
There are preferred ways of redirection, via htaccess for example, but this one is sometimes sufficient enough. To make it more cross-browser (I am not sure whether screen is supported in all browsers):
Edited by Dmit OE - Apr 17 2015 at 9:22am |
|
insaneman12
Newbie Joined: Apr 17 2015 Location: Arizona Status: Offline Points: 42 |
Post Options
Thanks(0)
|
I have only used this program for about a month and I have very little programing experience. The most I was able to do is have a window open saying hello using javascript. I spent a few hours trying to figure out how to word it right. This was the first way I got it to work. I was tring to get only the people on cell phones and some tablets to rediect to the mobile ver of the site while letting people on desktops and laptops stay on the normal site.
The script below is that an error code or what I would write into htaccess via free script? Witch by the way thanks for showing me that I never hit that botton yet. I have not completed the mobile web site yet but it should be done within the next 2 days its www.thevacdoctor.com and if anyone has a problem with it not redirecting please let me know. That way I can try and figure out how to get it to work properly. Hopefully without listing every mobile device lol. |
|
Dmit OE
Admin Group Joined: May 31 2012 Status: Offline Points: 5283 |
Post Options
Thanks(0)
|
"The script below" - what do you mean? The script I gave above is for JavaScript, for a Code Block.
|
|
insaneman12
Newbie Joined: Apr 17 2015 Location: Arizona Status: Offline Points: 42 |
Post Options
Thanks(0)
|
Ok like I said I am very new to scripting and am teaching myself java and html/css. That way I can use this program better and do some of the things I want the site to do.Thankyou for your help and ill try it in the program when I get home.
|
|
Blaster
Newbie Joined: May 12 2016 Location: Australia Status: Offline Points: 4 |
Post Options
Thanks(0)
|
how do I redirect using htaccess, I know I need to input a script but where in the htaccess do I insert it and what do I insert to redirect from my desktop website (/public_html) to my mobile site (/publi_html/mobile.1stchoicefire.com.au) ?
|
|
Dmit OE
Admin Group Joined: May 31 2012 Status: Offline Points: 5283 |
Post Options
Thanks(0)
|
There are solutions like this one (URLs need to be modified)
http://stackoverflow.com/a/4208300 Use Project->Htaccess, Add a command of type "Free Script" and post the code inside. |
|
BSS
Newbie Joined: Sep 02 2018 Status: Offline Points: 7 |
Post Options
Thanks(0)
|
Hi Dmit,
var width = ((typeof screen !== 'undefined') ? screen.width : null) I have applied the code that you provided as above into htaccess via Project --> htaccess --> Add a commend of type "Free Script" and post the code. But I got the error message from the MAIN WEBSITE as below: Internal Server Error The server encountered
an internal error or misconfiguration and was unable to complete your request. Please contact the
server administrator at webmaster@beenleighstorage.com.au to inform them of the
time this error occurred, and the actions you performed just before this error. More information about
this error may be available in the server error log. Additionally, a 500
Internal Server Error error was encountered while trying to use an
ErrorDocument to handle the request. Edited by BSS - Sep 04 2018 at 9:07am |
|
Dmit OE
Admin Group Joined: May 31 2012 Status: Offline Points: 5283 |
Post Options
Thanks(1)
|
This code was not at all intended for .htaccess! It's a Javascript code to be inserted into a Code Block (Source) type Javascript position StartBody (for example). The code for .htaccess you shoudl compose yourself based on http://stackoverflow.com/a/4208300
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |