javascript copy form from one page to another form

2019-06-11 02:53发布

Is it possible to copy values from a form on page x to a form on page y using javascript. The data is the same but just different pages and different applications?

4条回答
我想做一个坏孩纸
2楼-- · 2019-06-11 02:54

If it's just from one page to another you can append the data to the request as POST (with PHP) variables, or a simple query string (GET) and read them once the page has loaded/populate relevant fields - if the second page is loaded directly from the first.

If it needs to be retained until an unspecified time (when the user may have gone to other pages in the interim) you could look into using cookies.

how to get GET and POST variables with JQuery?

查看更多
我命由我不由天
3楼-- · 2019-06-11 03:03

Yes, you can do this. Using AngularJS you could use "search" variables and then plug these into the form. Using normal javascript you may be able to use a # with the data. Using PHP + normal javascript (more secure) you can send a POST to the page (which is a PHP page) and have the page, if the POST params with your values exist, put a javascript fragment on the page setting the values of the form when the page is done loading.

Cookies are also always an option :)

[EDIT]

After discussion, here is the solution to the question: GitHub

查看更多
甜甜的少女心
4楼-- · 2019-06-11 03:07

Actually, cross-tab JS is not allowed. I am not sure about bleeding-edge apis.

Theoretically, it is possible to do via local storage with a same-origin restriction. But you'd better don't mind this option.

Also, try to play with cookies.

查看更多
一夜七次
5楼-- · 2019-06-11 03:16

Try something like this:

window.onload = function() {
   var myValues;
   if (document.cookie) {
      // get your values onLoad
      myValues = document.cookie;
   } else {
      // set your values
      myValues = "..." // your values
      document.cookie = myValues;
   }
}
查看更多
登录 后发表回答