script to automatically redirect to...

User 564745 Photo


Registered User
51 posts

Hi i would like to see if there is a way to automatically redirect a visitor by looking at their screen resolution to the appropriate website version - ie a desktop user to a full html site and a 'mobile' user to a responsive layout - i will supply links to both versions on both sites - the reason being is that i will reduce the amount of content on a mobile site compared to the full blown website.

Any suggestions?
User 187934 Photo


Senior Advisor
20,266 posts
Online Now

It's very easy.
<script type="text/javascript">
<!--
if (screen.width <= 699) {
document.location = "mobile/mobilepage.html";
}
//-->
</script>
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2088758 Photo


Senior Advisor
3,111 posts

Jerome Trutmann wrote:
Hi i would like to see if there is a way to automatically redirect a visitor by looking at their screen resolution to the appropriate website version - ie a desktop user to a full html site and a 'mobile' user to a responsive layout - i will supply links to both versions on both sites - the reason being is that i will reduce the amount of content on a mobile site compared to the full blown website.

Any suggestions?


Just curious, have you had a chance to look at Responsive Layout Maker Jerome?

http://www.coffeecup.com/responsive-layout-maker-pro/

You will not need to worry about redirects because this tool will allow you to build only one website that will work on all devices. You can set breakpoints and hide content as the screen resolution gets smaller. There really isnt a need any longer to have and maintain two websites! Quite exciting I think.
Taking over the world one website at a time!

Steve Kolish
www.misterwebguy.com

YouTube Channel:
https://www.youtube.com/channel/UCL8qVv … ttneYaMSJA
User 187934 Photo


Senior Advisor
20,266 posts
Online Now

Steve wrote:

You will not need to worry about redirects because this tool will allow you to build only one website that will work on all devices. You can set breakpoints and hide content as the screen resolution gets smaller. There really isnt a need any longer to have and maintain two websites! Quite exciting I think.

This may not be the case with every situation.
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2088758 Photo


Senior Advisor
3,111 posts

Eric Rohloff wrote:
Steve wrote:

You will not need to worry about redirects because this tool will allow you to build only one website that will work on all devices. You can set breakpoints and hide content as the screen resolution gets smaller. There really isnt a need any longer to have and maintain two websites! Quite exciting I think.

This may not be the case with every situation.


Oh? Please tell :)
Taking over the world one website at a time!

Steve Kolish
www.misterwebguy.com

YouTube Channel:
https://www.youtube.com/channel/UCL8qVv … ttneYaMSJA
User 187934 Photo


Senior Advisor
20,266 posts
Online Now

display:none is not going to speed up a web page that much. The only savings you have is the rendering of the content to the screen. The browser still loads that content. If you have HD images, why would you make a mobile user load those Why not redirect to a mobile specific version of the page with images optimized for slower cell tower connections. The page could still be made in RLM.:P
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2088758 Photo


Senior Advisor
3,111 posts

Thanks for the explanation Eric! Still learning new stuff about coding every day.

display:none; is my best friend! and it seems to speed the load time up but maybe its just my perception of what's happening. I do realize you can build anything with RLM but do you still think its a good idea to have basically two websites to maintain?

I kinda of thought that was the whole purpose of building responsively.
Taking over the world one website at a time!

Steve Kolish
www.misterwebguy.com

YouTube Channel:
https://www.youtube.com/channel/UCL8qVv … ttneYaMSJA
User 187934 Photo


Senior Advisor
20,266 posts
Online Now

I'm not thinking in terms websites, I'm thinking web pages. I think that's where RLM can really shine because you will be able to be responsive even on a redirect for a specific reason. Responsive pages will fit at least 90% of the users out there.
Here's some interesting reading how Google looks at sites and the recommend handling of each situation.
https://developers.google.com/webmaster … one-sites/
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 564745 Photo


Registered User
51 posts

Hi Eric and Steve,

BTW i do have the full RLM pro and have had it for a little while - it makes this sort of new approach to web design much easier as i am slowly transitioning into html 5, css3 and jquery. - i so used to designing static layouts and using flash built with robust and generally crossbrowser friendly nested tables - i know smack smack - but it always worked across the board.

Thanks for the responce - at the moment i have clients that have a lot of detailed content and so the reason i was asking is that i want to handle their content differently and not squeeze all of it on a mobile device where people are browsing the mobile site for different information and the amount of time on there is minimal so minimal targeted content is the key here and if they want the full detailed site then they can click onto the the full site, which comes to my second question Eric.

So if the automatic redirect is on the landing page and the mobile user wants to go to the full site how do i then prevent it from throwing them back to the mobile site - the only thing i can think of is having the landing page on its own and then have seperate folders for the full site and one for the mobile.

Ps i am about to go off and check that link you put up.

User 187934 Photo


Senior Advisor
20,266 posts
Online Now

I finally had time to comeback to this. If you want to use a redirect but still offer your fullsite to mobile users, your going to either want to use some php or javascript. For this example I'm using javascript to accomplish the task.
This goes to the head of your mobile page.
<style>
#clicker{
display:none;
}
@media screen and (max-width: 700px) {
#clicker{
display:block;
}
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="jquery.cookie.js"></script>
<script>
function cookie_click()
{
var date = new Date();
var minutes = 1440; // 1440 equals one day
date.setTime(date.getTime() + (minutes * 60 * 1000));
$.cookie('redirect', '1', { expires: date });
}
</script>

Next place this code in the body of your mobile page where you want the link to your full site to show for mobile users.
<a href="full.html" id="clicker" onclick="cookie_click()">Full Site</a>


Then on your full site page place this code in the head of your page.
<script src="http://code.jquery.com/jquery-1.9.0.min.js"></script>
<script src="jquery.cookie.js"></script>
<script>
<!--
if ($(window).width() < 700 && $.cookie('redirect')!="1"){
window.location = "mobile.html";
}

//-->
</script>

You'll need to download jquery.cookie.js
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.