PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, October 15, 2022

[FIXED] How to create listener on document.createElement?

 October 15, 2022     createelement, document, dom, html, javascript     No comments   

Issue

How to create listener on document.createElement func?

For example, after

var canvas = document.createElement("canvas");

it was done automatically

console.log("createElement worked")

P.S. how to do the same but with different functions, for example toDataURL

var str = canvas.toDataURL("image/png");

it was done automatically

console.log("toDataURL worked")

Solution

You can override the original function and add your desired code extension at the beginning.

document.createElement = function (create) {
    return function() {
        console.log ('element created');
        return create.apply (this, arguments);
    };
}(document.createElement)

Example adapted from Hooking document.createElement using function prototype



Answered By - flappix
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing