我正在尝试运行一些小的JavaScript代码。我需要通过某个链接刷新页面上的数据,然后使用更新后的数据加载该页面。
由于我使用的平台限制,我必须在打开页面之前打开一个链接以更新数据。
我快速编写了一些JavaScript并进行了测试。它在Internet Explorer和Google Chrome中完美运行,但由于某种原因,在Firefox中似乎无法运行while循环。我不确定为什么它不起作用,因为我查找了语法并且似乎是正确的。
var refreshed = false;
while (refreshed != true) {
refreshpage = window.open('https://na10.salesforce.com/dash/dashboardRefresh');
refreshed = true;
refreshpage.close();
}
window.open('/dashboard', '__tab');
我尝试使用超时函数来关闭窗口。但我不确定是否使用正确。它会执行所有内容-包括循环中的内容-但从未关闭窗口。
以下是更新后的代码:
var refreshed = false;
var timeOut = setTimeout(function() {
refreshpage.close();
}, 1000);
while (refreshed != true) {
refreshpage = window.open('https://na10.salesforce.com/dash/dashboardRefresh');
refreshed = true;
clearTimeout(timeOut);
}
window.open('/dashboard', '__tab');
window.open
只是启动了该过程,然后您立即通过关闭窗口取消了它。为了确保请求得到可靠地发送,更不用说得到响应,您需要等待一段时间。 - T.J. Crowder