jquery - Android web browser not writing cookie in desktop view -
okay, using cookie generate mobile content on different device widths. site looks 1 way on desktop , reveals post content on mobile under 800px.
everything working except 1 little issue. when switch desktop view in mobile browser, seems happening in ios safari , android htc internet, cookie not being applied content isnt being generated. ive tried numerous searches , suggestions across web , havent found anything. amazing.
script in header:
<script type="text/javascript">var mql = window.matchmedia("screen , (max-width: 800px)") if (mql.matches){ var setcookie = function setcookie(name) { document.cookie = 'distancemobile=1; expires=0; path=/'; } setcookie('distancemobile');} else{ // else }</script> <script type="text/javascript"> var mql = window.matchmedia("screen , (min-width: 801px)") if (mql.matches){ var delete_cookie = function delete_cookie(name) { document.cookie = name +'=; path=/; expires=thu, 01 jan 1970 00:00:01 gmt;'; } delete_cookie('distancemobile');} else{ // else } </script>
php template:
<?php // template name: full width home get_header("home"); if ( wp_is_mobile($_cookie['distancemobile']) ) { echo '<style scoped> @media screen , (min-width: 801px){ #content {display: none !important;} }</style>'; get_template_part('custom-home-content'); //echo "hello!"; } elseif ($_cookie['distancemobile']) { get_template_part('custom-home-content'); //echo "hello!"; } else { // nada } get_footer(); ?>
here link site im working on. if shrink browser window below 800 have give 2 quick refreshes print content. otherwise visiting on device load fine.
again ive tried multiple things far. tried stripping away matchmedia , ive tried doing alert. seems not working in mobile browser when click desktop view.
regards.
* update php file test if mobile recognized , cookie firing* im returning spm in desktop view in mobile browser
<?php // template name: full width home get_header("home");if ( wp_is_mobile() ) { get_template_part('custom-home-content'); //echo "hello!"; } elseif ($_cookie['distancemobile']) { get_template_part('custom-home-content'); //echo "hello!"; } else { echo "spm jr."; } get_footer(); ?>
Comments
Post a Comment