I want to run a certain script only for devices with screen size of less than 769px. Environment is WordPress.
I already have
detectWidth function to find the width of the screen.
Ideally I want to do something like:
if(detectWidth() < 769)
then execute this code:
<script>
(function (d,s,n,id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s);
js.id = id;
js.className = n;
js.src = "https://example.com;
fjs.parentNode.insertBefore(js, fjs);
}(document,'script','p-mcd-sdk','mcd-sdk-jssdk'));
</script>
<pb-mcd embed-id="4f78-b5bb-b3547f1e51c8"></pb-mcd>
FYI this is the detectWidth function
function detectWidth() {
return window.screen.width || window.innerWidth || window.document.documentElement.clientWidth || Math.min(window.innerWidth, window.document.documentElement.clientWidth) || window.innerWidth || window.document.documentElement.clientWidth || window.document.getElementsByTagName('body')[0].clientWidth;
}