MutationObserver会检测通过外部样式表加载的更改吗?

时间:2017-06-06 19:05:53

标签: javascript android-webview mutation-observers external-js

我已将一个mutationObserver添加到由类名标识的div中。代码段如下所示。

var target = document.getElemenstsByClassName('uniqueClassName')[0];

var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;

var observer = new MutationObserver(function(mutation){
console.log('mutation happened');});

var config = {attributes:true};

observer.observe(target,config);

HTML页面有一个外部样式表,它为我们的目标保存了一些样式,即div,如下所述。

.uniqueClassName{
  height: 468px;
  width: 549px;
  margin-top: 0px;
  margin-left: 0px;
  position: absolute;
  z-index: 0;
  background-image: url("../images/page007.jpg");
  background-size: cover;
} 

我们需要在加载内容后获取图像的URL。但是变异观察者内部的语句不会被调用(目前是日志)。

HTML code:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<link rel="stylesheet" type="text/css" href="../css/font.css"/>
<link rel="stylesheet" type="text/css" href="../css/page004005.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=549, height=468"/>
<title>page004005</title>

</head>
<body>
<div class="page">
<div class="page">
<div class="uniqueClassName">

<article class="page_7_block_0">
</article>
</div>
</div>
</div>
</body>
</html>

0 个答案:

没有答案
相关问题