Reply To: Can we switch the theme on window resize function?

Home Forums Any Mobile Theme Switcher Can we switch the theme on window resize function? Reply To: Can we switch the theme on window resize function?

#3502
Bhaskar
Guest

Thank you for the quick response.
Just to let you know my scenario.
I am dealing with a site which has two version of theme,
i). desktop version and ii. mobile version
I have managed to switch the theme with the help of ajax on jquery’s window.resize function and overwriting the current document with html ajax response.

var mobilecall = false;
                var desktopcall = false;
            jQuery(document).ready(function() {
                
                
                if (jQuery(window).width() > 940) {
                    
                    switch_desktop_theme(true);
                }
                
                
                jQuery(window).resize(function() {

                    var width = jQuery(window).width();
                    if (width < 940 && mobilecall === false) {

                        desktopcall = false;
                        switch_mobile_theme(false);
                    } else if (width > 940 && desktopcall === false ) {

                        mobilecall = false;
                        switch_desktop_theme(false);
                    }
                });
            });
            function switch_mobile_theme(initial) {
                if (initial !== true) {
                    mobilecall = true;
                }
////                console.log('yay, mobile theme loaded');
//                jQuery.ajax({
//                    type: 'post',
//                    url: "<?php echo $mobile_url; ?>",
//                    dataType: 'html',
//                    success: function(result) {
////                            jQuery('html').html(result);
////                         preventDefault();
//                        document.write(result);
//                        document.close();
//                    }
//                })
            }

            function switch_desktop_theme(initial) {
                
                 if (initial !== true ) {
                    desktopcall = true;
                }

//                console.log('yay, mobile theme loaded');
                jQuery.ajax({
                    type: 'post',
                    url: "<?php echo $desktop_url; ?>",
                    dataType: 'html',
                    success: function(result) {
//                            jQuery('html').html(result);
//                         preventDefault();
                        document.write(result);
                        document.close();
                    }
                })
            }

        </script>