Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript XUL/Firefox扩展:确定主窗口的滚动位置_Javascript_Firefox_Xul - Fatal编程技术网

Javascript XUL/Firefox扩展:确定主窗口的滚动位置

Javascript XUL/Firefox扩展:确定主窗口的滚动位置,javascript,firefox,xul,Javascript,Firefox,Xul,我正在开发与主浏览器窗口交互的firefox侧栏。当侧边栏中的按钮被点击时,我需要能够确定用户在当前页面下滚动了多远 有人有什么想法吗?我似乎找不到正确的组合。我认为scrollTop和scrollHeight属性应该对您有所帮助。您可以将其与clientHeight属性结合使用 伪代码: scrollPercent = 100 if(clientHeight <= scrollHeight) { scrollPercent = (scrollTop / (scrollHeight

我正在开发与主浏览器窗口交互的firefox侧栏。当侧边栏中的按钮被点击时,我需要能够确定用户在当前页面下滚动了多远


有人有什么想法吗?我似乎找不到正确的组合。

我认为scrollTopscrollHeight属性应该对您有所帮助。您可以将其与clientHeight属性结合使用

伪代码:

scrollPercent = 100
if(clientHeight <= scrollHeight) {
    scrollPercent = (scrollTop / (scrollHeight - clientHeight)) * 100
}
scrollPercent=100

如果(clientHeight为其他可能正在寻找答案的人找到了答案:

window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
  .getInterface(Components.interfaces.nsIWebNavigation)
  .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
  .rootTreeItem.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
  .getInterface(Components.interfaces.nsIDOMWindow)
  .gBrowser.selectedBrowser.contentWindow.scrollY

以下内容将返回我的客户端高度:window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebNavigation).QueryInterface(Components.interfaces.nsidochelltreeitem).rootTreeItem.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow).gBrowser.selectedBrowser.clientHeight但是,在同一对象上调用scrollHeight始终返回等于clientHeight的值,而调用scrollTop始终返回0。对于格式设置,我深表歉意:/