2017-06-15 26 views
0

之前完成我写了下面的函数从日志文件中获取文本并显示在一个新的浏览器窗口的纯文本:火狐似乎在等待AJAX​​的异步更新DOM

function openLog(logFile) { 
    var win = window.open('', '_blank'); 
    var doc = win.document; 
    var title = doc.createElement('TITLE'); 
    var titleText = doc.createTextNode(logFile); 
    title.appendChild(titleText); 
    doc.head.appendChild(title); 
    doc.body.style.cursor='wait'; 

    $.ajax({ 
     type: 'GET', 
     url: '/getLog', 
     data: { logFile : logFile }, 
     success: function(log) {     
      var pre = doc.createElement('PRE'); 
      var preText = doc.createTextNode(log); 
      pre.appendChild(preText); 
      doc.body.appendChild(pre); 
      doc.body.style.cursor='default'; 
     }, 
     error: function() { 
      doc.body.style.cursor='default'; 
     } 
    }); 
}; 

的“等待”光标对于大型日志文件很有用。

在铬/ IE中,“等待”,而异步AJAX请求是在后台工作立即显示光标。在Firefox中,因为它似乎在等待AJAX​​功能来完成第一(一旦它被设定右后卫“默认”)仅显示“默认”光标。

是否有在Firefox中解决类似的问题?任何建议,将不胜感激。

+0

不,firefox不像您声称的那样行事 - 也许您将光标放在一个光标覆盖了身体光标样式的光标上 –

+0

哦,一世看 - 因为身在**新窗口是空的**,当然光标不是您所期望(惊讶它是在其他浏览器是诚实的 - 你怎么能有你的鼠标放在一个空元素??? ? ) –

回答

2

我很惊讶,它可以在任何浏览器 - 一个新打开的窗口将有一个身体不带内容因此大小为零 - 你怎么“悬停”在没有得到当前光标更改为指定一个?我认为Firefox是唯一正常运行的浏览器!

话虽这么说 - 伪代码

function openLog(logFile) { 
    var win = window.open('', '_blank'); 
    var doc = win.document; 
    var title = doc.createElement('TITLE'); 
    var titleText = doc.createTextNode(logFile); 
    title.appendChild(titleText); 
    doc.head.appendChild(title); 
    // change from here 
    var html = doc.documentElement; 
    html.style.cursor = 'wait'; 
    html.style.minHeight = '100vh'; 
    // changes finished 
    // 
    // dummy setTimeout for testing 
    setTimeout(function() { 
     // remove the cursor from HTML element 
     html.style.cursor = 'default'; 
    }, 4000); 
}; 
openLog('banana'); 

我会发布它作为一个可执行的代码段,但谁愿意让SO刚刚打开弹出式窗口此:P

我用body.parentElement(即HTML元素) - 因为这样做body结束了一个垂直滚动条

+0

好点。将更新 –

+0

有趣的是,用新的代码,现在我(偶尔)看到的东西铬奇怪。有时光标不会改变为“等待”,除非我移动鼠标。如果需要,应该很容易触发这个“运动”,但我认为这很奇怪。 –

+0

实际上在OP的Chrome版本中有些奇怪的东西。我无法从osX上的chrome中复制。 – Kaiido