1. 程式人生 > >JS-監聽整個頁面上的DOM樹變化

JS-監聽整個頁面上的DOM樹變化

# [線上預覽](https://jsfiddle.net/1010543618/fyf913t0/) ## 方法 - 使用《Web API 介面》的《MutationObserver》 [MutationObserver](https://developer.mozilla.org/zh-CN/docs/Web/API/MutationObserver) 網上查到的很多都是使用Mutation events的,但在MDN上一查這個事件已經廢棄了,並且推薦用MutationObserver替換掉 > Deprecated This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Avoid using it and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time. > Mutation events provide a mechanism for a web page or an extension to get notified about changes made to the DOM. Use Mutation Observers instead if possible. ```html

下述方法也可以監聽使用《谷歌頁面翻譯》時的DOM變化

The following way also can catch changes of DOM when using Google page translation

使用MutationObserver(Using MutationObserver)

Hello Mr. Word! ```