A
A
Abzal___072019-01-18 16:23:02
css
Abzal___07, 2019-01-18 16:23:02

How to disable the script for mobile phones?

how to disable script display on mobile devices

5c41dbcf693cb775876957.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Okhotnikov, 2019-01-18
@tsepen

Embed in html, this code include the script.js file on devices with a resolution of more than 990px ​​(replace at your discretion)

<script type="text/javascript">
{
if (screen.width > 990) document.write ('<script type="text/javascript" src="script.js" ></script>');
}
</script>

D
Dmitry Belyaev, 2019-01-18
@bingo347

add this module to your project:

const appleDevice     = /iP(hone|od|ad)/;
const applePhone      = /iPhone/i;
const appleIPod       = /iPod/i;
const appleTablet     = /iPad/i;
const androidPhone    = /(?=.*\bAndroid\b)(?=.*\bMobile\b)/i;
const androidTablet   = /Android/i;
const windowsPhone    = /Windows Phone/i;
const windowsTablet   = /(?=.*\bWindows\b)(?=.*\bARM\b)/i;
const otherBlackberry = /BlackBerry/i;
const otherOpera      = /Opera Mini/i;
const otherFirefox    = /(?=.*\bFirefox\b)(?=.*\bMobile\b)/i;
const sevenInch       = /(?:Nexus 7|BNTV250|Kindle Fire|Silk|GT-P1000)/i;

function match(regex, target = navigator.userAgent) {
    return regex.test(target);
}

export const isAppleDevice = match(applePhone) || match(appleIPod) || match(appleTablet) || match(appleDevice, navigator.platform);
export const isAndroidDevice = match(androidPhone) || match(androidTablet);
export const isWindowsDevice = match(windowsPhone) || match(windowsTablet);
export const isOtherDevice = match(otherBlackberry) || match(otherOpera) || match(otherFirefox);
export const isSevenInch = match(sevenInch);
export const isMobileDevice = isAppleDevice || isAndroidDevice || isWindowsDevice || isOtherDevice || isSevenInch;
export const isEmulator = isMobileDevice && !isWindowsDevice && (match(/Mac/, navigator.platform) || match(/Win32/, navigator.platform));

then import the desired flag, and check through if

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question