How to know if we are on the mobile page from a block ?

Post Reply
User avatar
polbrieuc
Advisor
Advisor
Posts: 98
Joined: Wed Dec 06, 2017 10:58 pm
Location: Vallirana
Station model: WH1080
Software: Cumulus
Contact:

How to know if we are on the mobile page from a block ?

Post by polbrieuc » Fri Dec 08, 2017 11:13 pm

Hi all,

Inside a block, I need to know if I am on the mobile or desktop page.
I tried to put a variable $isMobile = true; in the indexMobile.php but it is not recognized in my block.
Is there a global variable accessible from insde a block that let me know if I am on the mobile page ?
If not, is there another way to test it from PHP?
I found a dirty way to test it in javascript but I would need it in PHP
Javascript way :

Code: Select all

	var pathname = window.location.pathname; 
	var indexMobile      = 'indexMobile';     
	if(pathname.indexOf(indexMobile) !== -1) {
	// do something ..
	}
Thanks for your help.
Image

User avatar
Jachym
Site Admin
Site Admin
Posts: 1686
Joined: Fri Aug 18, 2017 10:12 pm
Location: Brno, Czech Republic
Station model: WH1080
Software: Meteobridge
Contact:

Re: How to know if we are on the mobile page from a block ?

Post by Jachym » Sat Dec 09, 2017 12:27 pm

Hi,
I think not, the problem is that the blocks are separate, they are loaded by the homepage by Javascript. So using PHP is probably impossible because you dont know which script will call it, this only happens after the homepage is being loaded and this is done by Javascript via Ajax request. This would require modification in the index files and adding it as a parameter in the Ajax call.

Post Reply