1

I want to show Propeller ads units (Monetag) only on the desktop version of my website because they interfere to much with my mobile design. The problem is that their ads come as a script so i can't style them through css.

Their ad units look like this:

<script>(function(d,z,s){s.src='https://'+d+'/400/'+z;try{(document.body||document.documentElement).appendChild(s)}catch(e){}})('mutcheng.net',5555555,document.createElement('script'))</script> 

Is there any way to execute this script only on screen size minimum 800px let's say?

isherwood
  • 58,414
  • 16
  • 114
  • 157
John Grischam
  • 224
  • 1
  • 19
  • 3
    read the screen size and exit out of the function..... – epascarello May 26 '23 at 15:30
  • 1
    I applaud you for addressing this even enough that I am going to upvote it. I see an increasing number of (some very popular) sites that present ads that make the mobile screen scroll jump around, and even reload the page while you are reading it - makes some of these site nearly or completely unusable IMHO. – Mark Schultheiss May 26 '23 at 15:36
  • @epascarello thank you for your comment. Can you please post an answer with the full code so a can accept it and upvote. I'm afraid i'm not able to do this by myself. Thank you – John Grischam May 26 '23 at 15:45
  • https://stackoverflow.com/questions/3437786/get-the-size-of-the-screen-current-web-page-and-browser-window – epascarello May 26 '23 at 15:48

1 Answers1

0

Thank you for your comments. This worked for me

    <script> if (window.innerWidth >= 800) {(function(d,z,s){s.src='https://'+d+'/400/'+z;try{(document.body||document.documentElement).appendChild(s)}catch(e){}})('mutcheng.net',5555555,document.createElement('script'))}</script>

In this solution, the provided script is enclosed within an if statement that checks if the window width (window.innerWidth) is 800 pixels or greater. If the condition is met, the original script will be executed as before. Otherwise, if the screen width is less than 800 pixels, the original script will not be triggered.

Please don't forget to replace your script with the code provided above, and it will ensure that the original script is executed only when the screen width is 800px or higher.

John Grischam
  • 224
  • 1
  • 19