I have a javascript widget (script1) that's placed in the <head>
on customer's websites. This creates an iframe, in which script2.js
is located.
These two scripts talk to each other via postMessage
. I have implemented a way where script2
asks the current URL from script1
, which then passes back the value of window.location.href
.
This works fine in Gatsby, but I discovered it doesn't work in React with Flux.
I'm not too familiar with these frameworks, but I guess this is because in such a SPA the script is loaded once.
How do scripts like Google Analytics get around this issue? How do they detect a page change and send the correct URL when that happens? Would love to understand more about how this works.
question from:
https://stackoverflow.com/questions/66052575/javascript-get-current-url-in-spa-eg-react-flux 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…