Is there a way through Wix code to determine the type of device (desktop, tablet, mobile phone) is being used and move to a particular page or play a certain .mp4 or .gif based on that information?
The wix-window formFactor property will let you know the device type.
You can then navigate to a page using the wix-location to() function.
Is there a URL for examples of the in action?
Your code should look like:
if(wixWindow.formFactor === 'Mobile') {
//Do stuff for mobile
} else {
//Do stuff from backend
}
Liran.
I’m very new to this so please excuse the inane questions but at “//Do stuff for mobile”, is there a "goto page “http://myamazingsite.com/mobilespash” or something like that? Or is there a function to test for tablets?
The “go to page function” is wixLocation.to() .
Can anyone tell me what is wrong with this code?
I’m getting errors on all but the “else” line
if(wixWindow.formFactor === ‘Mobile’) {
wixLocation.to(http://www.sudprop.com/about)
} else {
end if
}
Looks like you’re mixing languages there. JavaScript does not have an end if .
If you don’t want to do anything in the else, you can just leave it out.
I’m still getting errors on the top two lines, any idea what’s wrong?
Hi Watermark,
Enclose the url between two apostrophes.
if (wixWindow.formFactor === 'Mobile') {
wixLocation.to('http://www.sudprop.com/about')
} else {
}
also make sure to import both wixWindow and wixLocation
Not sure how to import those items.
Will the above work on tablets or just phones, Wix treats my iPad as a desktop device so want to make sure I’m heading down the right track. Need the small script 'Sudberry" and the bottom NOT ot show on ipads.
Possible?
Thanks
OK, figured that out but this is still going to the desktop home page on my phone and iPad.
Where am I not getting this?
Thanks
Here’s my code on my home page. Should it be on the “Site” tab in the WixXCode editor?
import wixWindow from ‘wix-window’;
import wixLocation from ‘wix-location’;
if (wixWindow.formFactor === ‘Mobile’) {
wixLocation.to(‘http://www.sudprop.com/about’)
} else {
}
Hi,
First, https://www.sudprop.com/about does not exist. Make sure to add a page with this url.
Next, change your code as follows:
import wixWindow from 'wix-window';
import wixLocation from 'wix-location';
$w.onReady(function () {
if (wixWindow.formFactor === 'Mobile') {
wixLocation.to('/about')
} else {
}
});
You should add the code to the Site tab if you want this script to execute on every page.
Add this to the page tab if you want this code to execute only in this specific page.