简体   繁体   English

JavaScript代码适用于chrome和IE,但不适用于Firefox

[英]JavaScript code works on chrome and IE but not Firefox

I'm trying to run some small JavaScript code. 我正在尝试运行一些小的JavaScript代码。 I need to refresh data on a page (using a certain link) then I want to load that page with the updated data. 我需要刷新页面上的数据(使用某个链接),然后我想用更新的数据加载该页面。

I basically have to open a link before opening the page to update the data due to the platform that I'm using. 由于我正在使用的平台,我基本上必须在打开页面之前打开链接来更新数据。

I quickly wrote some JavaScript and tested it. 我很快写了一些JavaScript并测试了它。 It works perfectly in Internet Explorer and Google Chrome, but for some reason it seems like it's not running the while loop in Firefox. 它在Internet Explorer和谷歌浏览器中运行良好,但出于某种原因,它似乎没有在Firefox中运行while循环。 I'm not sure why it's not working as I looked up the syntax and it seems correct. 我不确定为什么它不起作用,因为我查找语法,它似乎是正确的。

var refreshed = false;
while (refreshed != true) {
  refreshpage = window.open('https://na10.salesforce.com/dash/dashboardRefresh');
  refreshed = true;
  refreshpage.close();
}
window.open('/dashboard', '__tab');

I tried using a timeout function for closing the window. 我尝试使用超时功能来关闭窗口。 But I'm not sure if I'm using it right. 但我不确定我是否正确使用它。 It will execute everything - including what's in the loop - but it never closes the window. 它将执行所有操作 - 包括循环中的内容 - 但它永远不会关闭窗口。

Here's the updated code: 这是更新的代码:

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');

From the original post: 从原帖:

Here is what I used to get it to work: 以下是我以前的工作方式:

 var refreshed = false; while (refreshed != true) { refreshpage = window.open('https://na10.salesforce.com/dash/dashboardRefresh'); refreshed = true; var timeOut = setTimeout(function() { refreshpage.close(); window.open('/dashboard', '__tab'); }, 500); } 

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

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