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
55 views
in Technique[技术] by (71.8m points)

javascript - How to alternate between html files and send data amongst them?

We have two html files, file 1 and file 2. We want to switch from file 1 to file 2 and then submit a form in file 2. We want to take the data from the form and then use it in file 1. We are trying to stick with vanilla JS/html if possible. We are switching to file 2 initially inside an event listener and then we wanted to switch back after a successful form submit

    window.location.replace("file2.html");

The redirection from file1 to file2 went through, but the redirection back to file1 from file 2 was not executing.

We also noticed that the entire function that the window.location.replace was contained within was being executed before the switch but we wanted to use the data from the form submit in file 2 within that function.

question from:https://stackoverflow.com/questions/65925817/how-to-alternate-between-html-files-and-send-data-amongst-them

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

1 Reply

0 votes
by (71.8m points)

It would be useful to see your code within the onSubmit() form trigger, I guess you might not be handling the Event properly. Look into using [Event].preventDefault();, this will stop the form from re-rendering your file2.html before reaching the replace.

Here's a link for the MDN Web Docs.


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

...