Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3674050
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:48:28+00:00 2026-05-19T02:48:28+00:00

I have a large project in which I need to intercept assignments to things

  • 0

I have a large project in which I need to intercept assignments to things like element.src, element.href, element.style, etc. I figured out to do this with defineSetter, but it is behaving very strangely (using Chrome 8.0.552.231)

An example:

var attribs = ["href", "src", "background", "action", "onblur", "style", "onchange", "onclick", "ondblclick", "onerror", "onfocus", "onkeydown", "onkeypress", "onkeyup", "onmousedown", "onmousemove", "onmouseover", "onmouseup", "onresize", "onselect", "onunload"];
for(a = 0; a < attribs.length; a++) {
  var attrib_name = attribs[a];
  var func = new Function("attrib_value", "this.setAttribute(\"" + attrib_name + "\", attrib_value.toUpperCase());");
  HTMLElement.prototype.__defineSetter__(attrib_name, func);
}

What this code should do is whenever common element attribute in attribs is assigned, it uses setAttribute() to set a uppercased version of that attribute.

For some very strange reason, the setter works for only ~1/3 of the assignments.

For example with

element.src = "test"

the new src is “TEST”, like it should be

however with

element.href = "test"

the new href is “test”, not uppercase

then even when I try element.__lookupSetter__("href"), it returns the proper, uppercasing setter

the strangest thing is different variables are intercepted properly between Chrome and Firefox

help!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:48:29+00:00Added an answer on May 19, 2026 at 2:48 am

    This is not a good idea. Host objects (such as DOM elements) are not subject to the usual rules that apply to native JavaScript objects and can essentially do what they like, and all browsers to a greater or lesser extent take advantage of this fact. Browsers are not obliged to provide a prototype for host objects, and neither are they obliged to allow you to override getters and setters for host object properties, or respect any attempts to override default behaviour.

    I’d strongly recommend abandoning this approach and take a different approach instead, such as writing wrapper objects for DOM elements.

    UPDATE: Example of wrapper approach

    You can create wrapper objects for DOM elements and do all DOM manipulation through these wrappers. This is something many libraries (such as YUI) do. For example:

    function ElementWrapper(el) {
        this.domElement = el;
    }
    
    ElementWrapper.prototype = {
        // Wrap the DOM methods you need
        appendChild: function(child) {
            this.domElement.appendChild(child);
        },
    
        // Add custom behaviour, such as converting certain
        // property values to upper case
        setProperty: function(name, value) {
            if (/^(src|href|action)$/i.test(name)) {
                this.domElement[name] = value.toUpperCase();
            } else {
                this.domElement[name] = value;
            }
        }
    };
    
    var wrappedEl = new WrappedElement( document.getElementById("foo") );
    wrappedEl.setProperty("href", "http://www.google.com/");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large project in Vb.net which drives a web browser control around.
I have created a large Visual C++ 10.0 project which builds nicely within the
I'm working on a large project (for me) which will have many classes and
I have a project which uses a large library residing in its own repository.
I have a large project but I need only some folders in my svn
We have a large project mainly written in C# (services, multithreading etc.). However, the
I have a large project which was originally written in C#1.1 and is now
I have a large project for which I am attempting to use TDD. I
I have recently started a fairly large web project which is going to use
I have a large project with multiple Makefiles, and I need to modify the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.