Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Lay Theme Forum

  1. Home
  2. General Discussion
  3. scripts on mobile

scripts on mobile

Scheduled Pinned Locked Moved General Discussion
8 Posts 2 Posters 113 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sebastianpetrov
    wrote on Apr 30, 2024, 9:30 PM last edited by
    #1

    Hey,

    When on mobile does Laytheme load custom scripts differently?

    I've got a basic canvas embed set-up that works on desktop, but fails on mobile.

    3 main things happen for it to work.

    1. add event listener to listen for a .js file (i have this in the head)
    2. append canvas element to the dom (this in HTML bottom, wrapped in a newpageshown)
    3. load .js file (this right after 2, also wrapped in a newpageshown to ensure timing is right)

    On desktop: after the .js file is loaded it registers a message in the console. The event listener is pinged and triggers a chain of events + starts rendering in the canvas 👍

    On mobile the console logs appear the same as desktop, however it cycles through parts 1, 2, 3 and then nothing (can see it happening in chrome://inspect/#devices)

    The 1,2,3 set-up and the script itself works on mobile, I've verified this with an empty index.html file.

    It seems Laytheme is doing something I can't see to prevent it working on mobile.

    Without tearing laytheme apart I don't know if I can figure that out so I thought I would ask here. Maybe it's something really obvious for you @arminunruh or @mariusjopen ?

    Please let me know what you think?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      arminunruh
      Global Moderator
      wrote on May 1, 2024, 8:12 PM last edited by
      #2

      can you just insert the js without loading it in a newpageshown event

      instead of step 3
      just in html at bottom do:

      <script src"…"></script>

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sebastianpetrov
        wrote on May 2, 2024, 7:40 AM last edited by
        #3

        Hey Armin,

        Thanks for your reply - I really appreciate the help - I'm kind of stumped on this!

        I have tried that and it works on desktop, but not on mobile.

        On mobile if I keep things the same and run the .js script outside a newpageshown event this changes the console output significantly:

        The .js file gets loaded before the canvas code even begins to run.

        I was wondering at what point does newpageshown get fired and has laytheme executed all it's js by then or are there still things happening after?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          arminunruh
          Global Moderator
          wrote on May 2, 2024, 1:11 PM last edited by
          #4

          The .js file gets loaded before the canvas code even begins to run.

          u need to execute the js after the canvas element has loaded

          I was wondering at what point does newpageshown get fired

          once the html of the layout was inserted into the website

          1 Reply Last reply
          0
          • A Offline
            A Offline
            arminunruh
            Global Moderator
            wrote on May 2, 2024, 1:12 PM last edited by
            #5

            The .js file gets loaded before the canvas code even begins to run.

            just put the <script> tag that loads the js in "html at bottom"
            then it should be there after the canvas element has loaded

            then inside the js file write

            window.laytheme.on("newpageshown", function(){
            // write whatever should happen
            })

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sebastianpetrov
              wrote on May 2, 2024, 2:54 PM last edited by
              #6

              Hey Armin,

              Thanks for your reply and suggestion.

              Unfortunately that breaks it on desktop.

              Is there anything in Laytheme that hapens differently on mobile that could interfere with custom scrips?

              I'm going to look more closely at the code in the js file in case I've misunderstood how it pings the event listener.

              Thanks again, really appreciate the reply!

              1 Reply Last reply
              0
              • A Offline
                A Offline
                arminunruh
                Global Moderator
                wrote on May 4, 2024, 3:58 PM last edited by
                #7

                Unfortunately that breaks it on desktop.

                then u probably need to code it differently

                in your js code, combine both the desktop js and the mobile js, then in the js code determine if you are on mobile or desktop and run different code based on where u are

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sebastianpetrov
                  wrote on May 9, 2024, 10:10 AM last edited by
                  #8

                  Hey Armin,

                  Thanks again for your help!

                  It turns out the script was waiting for window.load to initialize which seems to fire a bit early on Laytheme, so I set-up a different custom event and listened for that instead.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes

                  8/8

                  May 9, 2024, 10:10 AM


                  I also code custom websites or custom Lay features.
                  💿 Email me here: 💿
                  info@laytheme.com

                  Before you post:
                  1. When using a WordPress Cache plugin, disable it or clear your cache.
                  2. Update Lay Theme and all Lay Theme Addons
                  3. Disable all Plugins
                  4. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"

                  This often solves issues you might run into

                  When you post:
                  1. Post a link to where the problem is
                  2. Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
                  3. If the problem is difficult to explain, post screenshots / link to a video to explain it
                  Online Users
                  Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com
                  laytheme.com
                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  8 out of 8
                  • First post
                    8/8
                    Last post
                  0
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Search