Hijacking DOM manipulations - Javascript Object

Javascript examples for Object:prototype

Description

Hijacking DOM manipulations

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//w ww . ja  v a2  s  .  c o  m
var el = document.getElementsByTagName('audio')[0];
Object.defineProperty(el, 'src', {
    set: function (newSrc) {
        console.log('they set src to ' + newSrc);
    }
});
el.src = 'http://example.com/sounds.mp3';
    }

      </script> 
   </head> 
   <body> 
      <audio></audio>  
   </body>
</html>

Related Tutorials