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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:35:09+00:00 2026-05-28T06:35:09+00:00

This code is being used on a Chrome Extension. When I call the "showOrHideYT()"

  • 0

This code is being used on a Chrome Extension.
When I call the "showOrHideYT()" function, I get a

"Uncaught ReferenceError: showOrHideYT is not defined | (anonymous
function) | onclick"

This code will search for youtube links in a page, and it will add a button (it’s really a div with an event) next to the link to show the iframe with the embedded video, pretty much like Reddit Enhancement Suite. Consider the code, per se, incomplete. I just want to know what am i missing when i call the "showOrHideYT(frameZES12345)" function.

if needed, i can provide manifest.json.

Thanks

function showOrHideYT(id)
{
    var YTvidWidth  = 420;
    var YTvidHeight = 315;
    frameYT=getElementById(id);
    console.log(frameYT.style.visibility);
    if (frameYT.style.visibility == "hidden")
        {
        frameYT.style.width = YTvidWidth+"px"; 
        frameYT.style.height = YTvidHeight+"px"; 
        frameYT.style.visibility = "visible";
        }
    if (frameYT.style.visibility == "visible")
        {
        frameYT.style.width = "0px"; 
        frameYT.style.height = "0px"; 
        frameYT.style.visibility = "hidden";
        }
};


// DOM utility functions
function insertAfter( referenceNode, newNode ) {
    if ((typeof(referenceNode) == 'undefined') || (referenceNode == null)) {
        console.log(arguments.callee.caller);
    } else if ((typeof(referenceNode.parentNode) != 'undefined') && (typeof(referenceNode.nextSibling) != 'undefined')) {
        if (referenceNode.parentNode == null) {
            console.log(arguments.callee.caller);
        } else {
            referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );
        }
    }
};
function createElementWithID(elementType, id, classname) {
    obj = document.createElement(elementType);
    if (id != null) {
        obj.setAttribute('id', id);
    }
    if ((typeof(classname) != 'undefined') && (classname != '')) {
        obj.setAttribute('class', classname);
    }
    return obj;
};
/////////////////////////////////////// 



$(document).ready(function() {

    
    var vidWidth    = 420;
    var vidHeight   = 315;
    var linksSemID  = document.getElementsByTagName("a") ;

    for (var i = 0; i < linksSemID.length; i++){
        if (/id=$/.test(linksSemID[i].href)) links[i].href += "1";
    }

    i=0;
    var youTubeRegExp = /(?:v=)([\w\-]+)/g;                 
    var forEach = Array.prototype.forEach;                  
    var linkArray = document.getElementsByTagName('a');     

    forEach.call(linkArray, function(link){                 
        linkArray.id="zes" + i++;                           
        
        var linkTarget = link.getAttribute('href');         
        if (linkTarget!=null)                               
            {
            if (linkTarget.search(youTubeRegExp) !=-1)      
                {
                
                console.log (linkTarget);
                idVideo=linkTarget.match(/(?:v=)([\w\-]+)/g);
                //idVideo = idVideo.replace("v=", "");      
                
                //add buton
                botaoMais = document.createElement('DIV');
                botaoMais.setAttribute('class','expando-button collapsed video');
                botaoMais.setAttribute('onclick','showOrHideYT(frameZES'+ i +')');
                insertAfter(link, botaoMais);

                
                
                //add iframe
                ifrm = document.createElement('IFRAME'); 
                ifrm.setAttribute('src', 'http://www.youtube.com/embed/'+ idVideo); 
                ifrm.style.width = '0px'; 
                ifrm.style.height = '0px'; 
                ifrm.style.frameborder='0px';
                ifrm.style.visibility = 'hidden';
                ifrm.setAttribute('id', 'frameZES' + i);
                insertAfter(link, ifrm);
                
                }
            }
    });  

});
  • 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-28T06:35:10+00:00Added an answer on May 28, 2026 at 6:35 am

    When you use setAttribute with a string, the event will be executed in the context of the page. The functions which are defined in a Content script are executed in a sandboxed scope. So, you have to pass a function reference, instead of a string:

    Replace:

        botaoMais.setAttribute('onclick','showOrHideYT(frameZES'+ i +')');
    

    With:

        botaoMais.addEventListener('click', (function(i) {
            return function() {
                showOrHideYT("frameZES"+ i);
            };
        })(i));
    

    Explanation of code:

    • (function(i) { ..})(i) is used to preserve the value of i for each event.
    • Inside this self-invoking function, another function is returned, used as an event listener to click.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When i run this code the paintComponent method is not being called It may
In code: //I know that to get this effect (being able to use it
It appears this code will request the file in Chrome and IE but not
I recently saw this code being used in a source file in a C++
Take this example code (ignore it being horribly inefficient for the moment) let listToString
Take this code snippet for example: window.location.href = 'mysite.htm#images'; Already being on the site
I have this code so far which perfectly but relies on there being a
In .NET, after this code, what mechanism stops the Thread object from being garbage
This isn't cross-platform code... everything is being performed on the same platform (i.e. endianess
I recently saw a bit of code that looked like this (with sock being

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.