PricingBlog

Get device innerheight and save it into a variable

  • yoelfdz-1213109948956016650

    yoelfdz

    1 year ago

    Trying to get the innerheight of the user's device and saving it into. variable. Tried to ask kapa but no success with that.

    I'm trying to use a custom action on load that get's the innerheight with an event that saves the event value in a variable, but apparently not getting the expected event data

    Custom action:
    function get_innerheight(args, ctx) {
    // Accessing the device's innerHeight
    var height = window.innerHeight;

    // Emitting the innerHeight value as an event
    ctx.triggerActionEvent({ deviceInnerHeight: height });
    }
  • jacobkofoed-1213136661307719741

    Jacob Kofoed

    1 year ago

    Looks like you are missing the name of the action event you want to call. The first argument is the name, the second is the data. So perhaps something like:

    ctx.triggerActionEvent("deviceInnerHeight", height)
    ❤️1
  • I think our docs are lacking a bit, so I'm going to make sure to update it right away
  • jacobkofoed-1213139755945164890

    Jacob Kofoed

    1 year ago

    I have updated our docs a bit, maybe this will help a bit:
    - https://docs.nordcraft.com
    - https://docs.nordcraft.com
    ❤️1
  • yoelfdz-1213139831211819028

    yoelfdz

    1 year ago

    True! Solved. For anyone looking at this the correct function is:

    function get_innerheight(args, ctx) {
    // Obtiene el valor de innerHeight
    const height = window.innerHeight;

    // Activa el evento en Toddle con el nombre y los datos
    ctx.triggerActionEvent("deviceInnerHeight", { innerHeight: height });
    }
  • jacobkofoed-1213139879878205451

    Jacob Kofoed

    1 year ago

    Glad it worked! 💪
  • We are working on getting type-safety into the code-editor, but no ETA right now
  • yoelfdz-1213140109319344178

    yoelfdz

    1 year ago

    Thank you Jacob !