【发布时间】:2019-10-26 19:13:15
【问题描述】:
我有两个 html 页面。一个是display.html,另一个是test.html。在 test.html 我有一个按钮:
<button id="btn" class="btn btn-default commonButton" type="button">Go</button>
在另一个页面上,我正在显示一些内容。两个页面的javascript代码在同一个js文件中。
我想知道的是,如果我点击test.html 中的按钮,我如何重新加载/刷新我的另一个页面display.html?
我正在做这样的事情
$("#btn").on('click',function() {
window.location = 'display.html';
});
这会将我重定向到那个页面,这不是我想要做的。
有按钮的第1页
<button id="btn" class="btn btn-default commonButton" type="button">
</button>
第1页JS代码
Imagehandeler
function Imagehandeler()
{
$.ajax({
$("#btn").click(function() {
localStorage.setItem('doRefresh', 'yes');
});
// ajax callinge here
}); //ajax closing
} //function closing
现在在第 2 页 JS
fullCode();
function fullCode()
{
window.addEventListener('storage', function(e) {
var canIRefresh = storage.getItem('doRefresh');
if(canIRefresh == 'yes'){
console.log(canIRefresh)
localStorage.setItem('doRefresh', 'no');
location.reload();
}
});
// Some codes to displaying data
}
这就是我的想法
【问题讨论】:
-
这两个页面有什么关系?例如,一个是否包含在另一个内的 iframe 中?
-
不确定我是否正确解释了这个问题,但这不是网站的工作方式。就您的浏览器而言,这两个页面都是单独的页面。因此,除非一个页面打开另一个页面,否则它们不会相互引用。您要么必须使用服务器充当中间人,要么让一个页面打开另一个页面,以便它们相互引用。
-
你到底想要什么?
-
@ArshpreetWadehra 从一个页面我想重新加载或刷新其他页面
-
@Shilly 没有关系
标签: javascript java jquery servlets