简体   繁体   English

当页面被重定向时,如何在正在加载的页面的 innerhtml 中使用 javascript 变量?

[英]As a page is redirected how can I use a javascript variable in the innerhtml of the page being loaded?

foo() {
    var fooVar=7;
    location.assign("otherPage.php");
    otherPageobject.html=fooVar;
}

The code running on one page can't affect anything on another page, because only one page can be loaded/active at a time.在一个页面上运行的代码不会影响另一个页面上的任何内容,因为一次只能加载/激活一个页面。 What you can do is send your value to that next page.可以做的就是将您的价值发送到下一页。 For example:例如:

location.assign("otherPage.php?fooVar=" + fooVar);

Then in that other page you can get the value from the query string and use it as you see fit.然后在另一个页面中,您可以从查询字符串中获取值并按照您认为合适的方式使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM