Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
300 views
in Technique[技术] by (71.8m points)

Javascript get current url in SPA (eg React / Flux)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...