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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:28:24+00:00 2026-06-07T23:28:24+00:00

The code below works in Chrome and IE(8), but firefox says that overlay is

  • 0

The code below works in Chrome and IE(8), but firefox says that “overlay is not defined”.
Using this.overlay or [this.overlay] doesn’t work either. What causes the difference and how to fix it in Firefox?

the code:

var ol = {
overlay: document.getElementById("overlay"),
build: function(e){
    //todo: build elements dynamically
},
open: function(){
    overlay.style.display = "block";
    centerVertically();
    ol.build();
},
close: function(){
    overlay.style.display = "none";
}
};

Thanks in advance.

EDIT:
The solutions work standalone (JSfiddle ), but when I use the code in my project it fails. It makes absolutely no sense. See this screencap mashup:
Image link

EDIT #2:

Moving my script tag to the bottom of DOM fixed everything. I don’t know why I didn’t think of that. That was probably the issue from the start – Chrome and IE just handle my stupidness better even with closure problems.

But, since I received your replies I now write safer code and know how to properly access object’s properties inside the object. Thanks!

  • 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-07T23:28:27+00:00Added an answer on June 7, 2026 at 11:28 pm

    Just like you do when you are referencing a method, you just need to add the object scoping when you are referencing ‘overlay’.

    So in your function just do “ol.overlay.style.display” and you should be fine.

    var ol = {
        overlay: document.getElementById("overlay"),
        build: function(e){
            //todo: build elements dynamically
        },
        open: function(){
            ol.overlay.style.display = "block";
            centerVertically();
            ol.build();
       },
       close: function(){
            ol.overlay.style.display = "none";
       }
    };
    ol.open();
    

    The way you have it now, it’s looking for a global JS variable outside of the ‘ol’ object scope.

    EDIT As @Matt Ball refers to in a comment below (something I meant to add to this). You should make sure that you only get your ‘overlay’ element when the DOM has finished loading.

    You could do that through a document.ready pattern or you could do a lazy loading pattern within your ‘ol’ functions. I’d recommend the document.ready pattern and changing your ‘ol’ object to have the overlay default to null and define it at document ready (or put it in an init type method that you call on document ready), either is fine.

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

Sidebar

Related Questions

The below code works fine in Chrome, but doesn't work correctly in Firefox. In
The code below works fine in Chrome but does not work in Firefox. The
The below code works in Firefox but not in Google Chrome: <!DOCTYPE html> <html>
My Issue: The code below works for me in FireFox and Google Chrome, but
My code (Below) works in Internet Explorer, but not in Chrome, Safari or Mozilla
The code below works well in Safari but in Chrome and Firefox the form
The code below works in FF, Safari, Chrome. But IE is giving me issues.
How to detect escape key press in IE, Firefox and Chrome? Below code works
I have some jQuery code which works great in Firefox and Chrome, but does
My CSS code below is working fine in Chrome, but isn't working in Firefox.

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.