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 8228657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:31:56+00:00 2026-06-07T16:31:56+00:00

I am writing a bookmarklet which performs some function on a page. As part

  • 0

I am writing a bookmarklet which performs some function on a page. As part of this function I need to use getElementsByClassName. However, during testing I found that several websites have redefined getElementsByClassName to a custom method. Presumably this was done in order to support getElementsByClassName in all browsers.

The implementation of custom getElementsByClassName is a bit sloppy and fails for several of my use cases. Is there any way I could get the original definition of getElementsByClassName?

In the chrome javascript console: getElementsByClassName points to a native function. Is there a way to access this native function, now that getElementsByClassName has been redefined?

  • 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-06-07T16:31:57+00:00Added an answer on June 7, 2026 at 4:31 pm

    There is a solution, but it is not robust. See the disclaimer at the bottom.

    If you open a new window you will have access to its unmodified methods. I can think of two ways to open a new window: using window.open, and in an iframe. The iframe is less obtrusive because it won’t distract the user by opening new browser windows or triggering pop-up blockers.

    // Runs fn with a clean window reference
    function getCleanReferences(fn) {
        var iframe = document.createElement('iframe');
        iframe.style.display = 'none';
        document.body.appendChild(iframe);
        var newWindow = iframe.contentWindow;
        iframe.parentNode.removeChild(iframe);
        return fn(newWindow);
    }
    

    Some browsers won’t like removing the iframe. If you want this to work in Safari or Firefox, delete the removeChild line. Next, you will want to get the getElementsByClassName method from the new window.

    var nativeGetElementsByClassName = getCleanReferences(function(newWindow) {
        var getElementsByClassName = newWindow.document.getElementsByClassName;
        return function(className) {
            return getElementsByClassName.call(window.document, className);
        };
    });
    

    This is pretty much cross-browser, except that IE doesn’t like getElementsByClassName in quirks mode or before version 9 (which you have little control over in a bookmarklet). Here’s a jsfiddle: http://jsfiddle.net/theazureshadow/vdqYG/

    And if you’re curious about my experiments with importing other methods, take a look at this jsfiddle: http://jsfiddle.net/theazureshadow/ccFG3/

    DISCLAIMER: Using methods from other windows in the context of the current one is dangerous, undefined territory. If you choose to use this fragile approach, make sure you test for cross-browser compatibility. My tests showed major differences in how different browsers treat this approach. You should not use this on a production site, but it might be okay for a personal bookmarklet. It is probably much safer to just include your own version of whatever method you want to use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing this bookmarklet in Javascript, which is also calling some JQuery objects. The
I am writing a bookmarklet in which I want to use the jquery forms
I am writing a simple bookmarklet that runs on youtube page and fetch some
I'm writing a bookmarklet which needs to work in the context of pages whose
Writing a function to generate and push some random data inside of the unknown
Writing some regex to help process street addresses. However, I'm unsure if regex is
Writing a program in which I need to split strings from a struct linked
I'm writing a bookmarklet and I need to be able to prompt the user
Writing a small HTML web page with some very simple Javascript in it, I
Writing my first silverlight application. I need to deliver some bitmap that the customer

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.