PricingBlog

best practices for page redirects on load?

  • rscott-1211861905786929212

    Bishop

    1 year ago

    It's very hard to edit the site when you do page redirects when someone isn't logged in.

    What is best practice for making this tolerable/workable?
  • the_guy01-1211981415210819604

    the_guy

    1 year ago

    You can simply check the current URL, if it is toddle.dev do not redirect

    You could enable/disable this using a variable so you can switch behavior
  • the_guy01-1211981792899371018

    the_guy

    1 year ago

    1211981792685596712-Screenshot_2024-02-27_at_14.22.52.png
  • 1211981855545360414-Screenshot_2024-02-27_at_14.23.06.png
  • yoelfdz-1211981987691233300

    yoelfdz

    1 year ago

    Agree, I usually create an admin control pannel to enable or disable things like that
  • the_guy01-1211982557936226374

    the_guy

    1 year ago

    Expanded by the variable

    Use_editor_Redirect = true

    means you will redirect even in the editor.
    To turn it off, set it to false
    1211982557726638100-Screenshot_2024-02-27_at_14.25.15.png
  • the_guy01-1211985029782306816

    the_guy

    1 year ago

    I just realised the setup doesnt work becuase the hostname is different in the UI preview compared to actually running the function within the project

    UI Preview uses toddle.dev while the Project actually runs on its toddle.site subdomain

    Team toddle
    1211985029555687484-Screenshot_2024-02-27_at_14.34.51.png
  • andreasmoller-1211985709624463420

    Andreas Møller

    1 year ago

    This is a bug. we will look into it 🙂
  • the_guy01-1211985877631238144

    the_guy

    1 year ago

    @Bishop
    For now, just check the variable like this until hostname actually returns toddle.dev
    1211985877346291762-Screenshot_2024-02-27_at_14.38.52.png
  • andreasmoller-1211986000746647562

    Andreas Møller

    1 year ago

    Yes that is a good temprary fix.
  • the_guy01-1211986008552513556

    the_guy

    1 year ago

    Thanks, is there a way to check if you are in the editor reliably if hostname doesnt work as intended?
  • andreasmoller-1211986625370914817

    Andreas Møller

    1 year ago

    You want to check window.top.location.hostname this would require a custom formula

    function getTopFrameHostname() {
    return window.top.location.hostname;
    }
  • the_guy01-1211988356041416715

    the_guy

    1 year ago

    I tried that, it returns null
  • the_guy01-1211988731817361468

    the_guy

    1 year ago

    I already have a suspicion that custom formulas arent available by the time the page is loaded.
    I have seen different things now that lead me to this assumption, this is one of them.

    Creating a "flatten object" function and using this is another one that I mentioned in general.
    I can make a more detailed video/description if that helps
  • 1211988824977055814-Screenshot_2024-02-27_at_14.50.49.png
  • 1211988882275434536-Screenshot_2024-02-27_at_14.51.01.png
  • 1211988963162591232-Screenshot_2024-02-27_at_14.51.22.png
  • the_guy01-1211989322962706462

    the_guy

    1 year ago

    When you show the top frame hostname on the page, it says the hostname in the HTML Tree but NULL on the Preview
    1211989322765443082-Screenshot_2024-02-27_at_14.52.29.png
  • the_guy01-1211989715377725480

    the_guy

    1 year ago

    Same if you would assign top frame hostname to a variable
    1211989715100893184-Screenshot_2024-02-27_at_14.54.11.png
  • mdxwired-1277120578007990283

    mdxwired

    1 year ago

    I am also still getting bizarre results trying to identify whether my page is executing within the UI or not. In the attached screen-grab you can see that I am checking hostname and in-formula as well as what the editor indicates the current value of the simple text field (the green circles) that I set up to debug with... it's correct. But, then the actual value displayed in-page (red circle) shows the run-time hostname. Thoughts?
    1277120577794084986-2024-08-24_23-13-42.png