I've optimised my site for mobile by including a seperate style sheet. I have created a switch to desktop button which works perfectly using the code below.
$('#desktop-site-click').click(function() {
event.preventDefault();
document.cookie = 'cookiewidthset=yes'
$('link[href="http://www.url.com/assets/style-mobile.css"]').prop('disabled', true);
$('head').remove('<meta name="viewport" content="width=device-width, initial-scale=1"/>');
});
This works but I need a way of creating a cookie so when the user navigates to another page the function above is remembered and they still see the desktop variant of the site.
Thanks
Assign the cookie path to the root, so that it applies to the whole site (root and descendants):
document.cookie = "cookiewidthset=yes; path=/";
;path=path (eg, '/', '/mydir') If not specified, defaults to the current path of the current document location.
https://developer.mozilla.org/en-US/docs/Web/API/document/cookie
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.