[筆記] DOM 變更監聽器 -- MutationObserver
# Example
開發中的 [webedtior](https://app.stoneapp.tech/editor) 的一段 code
```javascript
let observer = new MutationObserver((mutation, observer) => {
parent.postMessage({
"status": "titleUpdate",
"title": (document.title || "No title")
}, "*");
});
observer.observe(document.querySelector('title'),{
childList: true,
subtree: true
});
```
reference:
- https://stackoverflow.com/questions/2497200/how-to-listen-for-changes-to-the-title-element
- https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
2019-06-28 18:14:43
留言
Last fetch: --:--
現在還沒有留言!