Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.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
getCSSProperties发出了一个Javascript错误_Javascript_Css - Fatal编程技术网

getCSSProperties发出了一个Javascript错误

getCSSProperties发出了一个Javascript错误,javascript,css,Javascript,Css,调用时,它会显示此错误 它给出了这个错误 function getStyle(el, cssprop) { if (el.currentStyle) { // IE return el.currentStyle[cssprop]; } else if (document.defaultView && document.defaultView.getComputedStyle) { // Firefox return document.defaultView

调用时,它会显示此错误 它给出了这个错误

function getStyle(el, cssprop) {
  if (el.currentStyle) { // IE
    return el.currentStyle[cssprop];
  } else if (document.defaultView && document.defaultView.getComputedStyle) { // Firefox
    return document.defaultView.getComputedStyle(el, "")[cssprop];
  } else { // try and get inline style
    return el.style[cssprop];
  }
}
因此,函数调用是
findOpacity(window.thirddiv,1)
findOpacity
调用
getStyle
findOpacity
的代码如下:

NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument arg 0 [nsIDOMWindow.getComputedStyle]
return document.defaultView.getComputedStyle(el, "")[cssprop];
函数findOpacity(节点,最小值){
if(node==document.body){
返回getStyle(document.body,'opacity')
我不知道到底是什么原因导致您出现问题,但请尝试

function findOpacity(node, minValue) {
    if(node==document.body) {
        return getStyle(document.body, 'opacity') < minValue
            ? getStyle(document.body, 'opacity')
            : minValue;
    } else {
        return findOpacity(node.parentNode, getStyle(node.parentNode, 'opacity'))
            < minValue
            ? findOpacity(node.parentNode, getStyle(node.parentNode, 'opacity'))
            : minValue;
    }
}
注意,你应该避免像这样的事情

function findOpacity(node, maxValue) {
    var val = node===document.body
        ? getStyle(document.body, 'opacity')
        : findOpacity(node.parentNode);
    if(maxValue !== void(0)) val = Math.min(val, maxValue);
    return +val;
}
getStyle(document.body,'opacity')
因为您可以计算两次
getStyle(document.body,'opacity')
。此外,
minValue
是最大值,而不是最小值

你的问题

问题在于
window.thirddiv
不是一个html元素,而是一个。而且不能将
document.defaultView.getComputedStyle
与XPC包装一起使用


我猜你是在用特权编写GreaseMonkey脚本。然后,您应该阅读,要获得真正的html元素,请使用
window.thirddiv.wrappedJSObject
。问题是您的代码容易受到攻击,恶意脚本可能会访问特权方法,如
GM_xmlhttpRequest


如果不创建GM脚本,可以使用
XPCNativeWrapper.unwrap(obj)
打开XPC包装。同样,这是一种不安全的做法。

是的,但在浏览器中没有得到很好的支持。到底什么是
el
?@jimmyweb我已经针对所有浏览器进行了测试。您是否有更好的功能来获取CSSP属性。Thanks@SLaksel是定义css属性的元素请描述您想要实现什么,因为脱离上下文的代码是useless@SwarajChhatre它对我有用。我认为您的
窗口。thirddiv
不是html元素。window.thirddiv在控制台上提供ot。它确实存在。@SwarajChhatre啊,等等。它不是一个html元素,但window.thirddiv.wrappedJSObject发出“undefined”。并非所有XPC包装器都有属性。然后,尝试
XPCNativeWrapper.unwrap
getStyle(document.body, 'opacity') < minValue
    ? getStyle(document.body, 'opacity')
    : minValue;