Swapping text depending on mobile or desktop

Hi all,

So, I am attempting to change the text of a text box based on whether the user is viewing the site on a computer or a mobile device. The problem I am running into is using the editor. When I preview the desktop site the text changes to that of the desktop text, but when in the mobile editor the text does not change accordingly.

I think the problem I am running into is that the wixWindow.formFactor is not being correctly set when viewing the site through the editor. Does anyone know if the formFactor actually changes to “Mobile” when viewing the site in the mobile editor, or does it remain “Desktop”? And if it does remain “Desktop” is there a way to fake it out so I can make sure that the code is functioning properly? I tried manually setting it to “Mobile” but I received an error basically telling me I can’t do that.

Thanks all.

Hi Altruin,

Yes you are right, if you console log the wixWindow.formFactor it will return desktop for both cases ( mobile - desktop ) in the preview mode. Regarding the way to test the code if it’s working properly, you can publish your website then take the URL to test it on your mobile, Or if you only want to hide some elements in the mobile version, you can hide elements without coding, just click on the element in the mobile editor and click hide element (eye icon ).

Here is a good documentation about displaying elements on mobile only : Velo Tutorial: Displaying Elements in Mobile Only | Help Center | Wix.com

Hope this helps you.
Best,

Mustafa