Is there a way to get scripts to load in project iframes, with localStorage for dark mode intact? [solved]

I have a fair amount of projects with a dark mode button and/or some other javascript being loaded at the top of the page with

document.addEventListener('DOMContentLoaded', () => {  // etc..

The JS doesn’t work when I’m viewing the projects within an iframe (if the url for it is something like glitch.com/~myproject). Is there an accepted way around this?

I just tried moving the scripts to a separate js file and used defer, which also didn’t work. Which I expected…

So it turns out Glitch doesn’t like the localStorage stuff in my dark mode setup. If I comment the dark mode stuff out, the rest of the JS works.

Is this a security issue, and does anyone know of a way around it, hopefully without rewriting my code?

edit: here’s my code - Glitch

Solution: I googled the error I was getting in the console and realized the problem was my Chrome settings. Under chrome://settings/cookies, I had ‘Block third-party cookies’ checked off. I now have ‘Block third-party cookies in Incognito’ checked, and everything is fine.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.