Announcement

Collapse
No announcement yet.

How to query forum width in static html module

Collapse
X
Collapse
First Prev Next Last
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to query forum width in static html module

    I'd like to use a static HTML module to display some banner ads
    I'm looking for some way to find out the users screen size/width, so for example

    if forum-width = 1200 px show Big ad
    if forum-width = 968 show smaller ad

    what is the correct code for that?

    #2
    that would have to use the screen.width control

    Code:
    <p>Click the button to display the total width of your screen, in pixels.</p>
    
    <button onclick="myFunction()">Try it</button>
    
    <p id="demo"></p>
    
    <script>
    function myFunction() {
        var x = "Total Width: " + screen.width + "px";
        document.getElementById("demo").innerHTML = x;
    }
    </script>
    this should at least get you started, this is javascript that can be directly entered into a static HTML module

    Run it and you will see that it shows the screen width as as result in the format...Total Width: ####px

    So then you'd need an if function to display one ad or the other based on a breakpoint (i.e. if screen.width < 800px then do this, else do this etc.)

    Comment


      #3
      Thanks, thaty helps a lot

      Comment


        #4
        What's your ad provider? Google Adsense supports responsive ad units.
        Helpful? Donate. Thanks!
        Buy me a coffeePayPal QR Code
        Fast VPS Host for vBulletin:
        A2 Hosting & IONOS

        Comment

        Users Viewing This Page

        Collapse

        There is 1 user viewing this forum topic.

        • Guest Guest

        Latest Posts

        Collapse

        Working...
        X
        Searching...Please wait.
        An unexpected error was returned: 'Your submission could not be processed because you have logged in since the previous page was loaded.

        Please push the back button and reload the previous window.'
        An unexpected error was returned: 'Your submission could not be processed because the token has expired.

        Please push the back button and reload the previous window.'
        An internal error has occurred and the module cannot be displayed.
        There are no results that meet this criteria.
        Search Result for "|||"