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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:08:59+00:00 2026-06-04T06:08:59+00:00

I am new to this so please be kind (; I’m trying to use

  • 0

I am new to this so please be kind (;
I’m trying to use Greasemonkey to add div-layers and I just can’t get it to work properly.

My final goal is to let the user draw a window on the screen (or make two clicks) and everything but this area should kind of fade out (added dark div-layers).
But, for now I just wanted to add a visible layer to every site. Here is my first try (which did not work at all) :

var CSSNJE = '#Test_divnje {height:100px; width:100px; background-color:red;  
             position:absolute; top: 200px; left: 400px; z-index:2147483647}';
var CSSNJE = '<style type="text/css">'+ CSSNJE +'</style>';
  document.write(CSSNJE);

var DIVNJE = '<DIV id="Test_divnje"></DIV>';
  document.write(DIVNJE);

I Googled this piece of code, which works for some pages but not many:

makeLayer('LYR1',400,250,100,100,'red',1,2147483647);

function makeLayer(id,L,T,W,H,bgColor,visible,zIndex) {
  if (document.getElementById) {
    if (document.getElementById(id)) {
      alert ('Layer with this ID already exists!');
      return;
    }
    var ST = 'position:absolute'
    +'; left:'+L
    +'; top:'+T
    +'; width:'+W
    +'; height:'+H
    +'; clip:rect(0,'+W+','+H+',0)'
    +'; visibility:'
    +(null==visible || 1==visible ? 'visible':'hidden')
    +(null==zIndex  ? '' : '; z-index:'+zIndex)
    +(null==bgColor ? '' : '; background-color:'+bgColor);

    var LR = '<DIV id='+id+' style="'+ST+'"></DIV>'

    if (document.body) {
     if (document.body.insertAdjacentHTML)
         document.body.insertAdjacentHTML("BeforeEnd",LR);
     else if (document.createElement
          &&  document.body.appendChild) {
      var newNode = document.createElement('div');
      newNode.setAttribute('id',id);
      newNode.setAttribute('style',ST);
      document.body.appendChild(newNode);
     }
    }
   }
  }

First I thought the z-index of my div-layer was too low and my div-layer was just behind the visible layers (that’s why my index is so high right now) but using a higher index did not help.

I also tried do use position:fixed because I read that this would maybe help, but it didn’t.

How can I make an overlay that works?

  • 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-04T06:09:00+00:00Added an answer on June 4, 2026 at 6:09 am

    Since you are starting out, use jQuery and (in this case) jQuery-UI. It makes coding vastly simpler, and will save you a ton of grief from trying to “reinvent the wheel” the hard way.

    In jQuery-UI, two-thirds of what the question asks for is accomplished in 1 line of code:

    $("#dialog").dialog ( {modal: true} );
    

    Note that this is drag-able and sizable, right out of the box!

    With Greasemonkey on Firefox, there is almost no cost to using jQuery, and jQuery-UI, either. The scripts are downloaded one time (when the script is installed or edited) and then run from the local machine. It’s nice and fast.

    Here is a complete Greasemonkey script that adds “a layer” with a re-sizable window to Stack Overflow pages:

    // ==UserScript==
    // @name        _Add a User-interactive layer to a web page.
    // @namespace   _pc
    // @include     http://stackoverflow.com/*
    // @require     http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
    // @require     http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js
    // @resource    jqUI_CSS  http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css
    // @resource    IconSet1  http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/images/ui-icons_222222_256x240.png
    // @resource    IconSet2  http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/images/ui-icons_454545_256x240.png
    // @grant       GM_addStyle
    // @grant       GM_getResourceText
    // @grant       GM_getResourceURL
    // ==/UserScript==
    
    //--- Add our custom dialog using jQuery. Note the multi-line string syntax.
    $("body").append (
        '<div id="gmOverlayDialog">                                                     \
         Resize with the control in the lower-left, or by dragging any edge.<br><br>    \
                                                                                        \
         Click the x, or press the Escape key to close.                                 \
         </div>                                                                         \
        '
    );
    
    //--- Activate the dialog.
    $("#gmOverlayDialog").dialog ( {
        modal:      true,
        title:      "Click and drag here.",
        zIndex:     83666   //-- This number doesn't need to get any higher.
    } );
    
    
    /**********************************************************************************
        EVERYTHING BELOW HERE IS JUST WINDOW DRESSING (pun intended).
    **********************************************************************************/
    
    /*--- Process the jQuery-UI, base CSS, to work with Greasemonkey (we are not on a server)
        and then load the CSS.
    
        *** Kill the useless BG images:
            url(images/ui-bg_flat_0_aaaaaa_40x100.png)
            url(images/ui-bg_flat_75_ffffff_40x100.png)
            url(images/ui-bg_glass_55_fbf9ee_1x400.png)
            url(images/ui-bg_glass_65_ffffff_1x400.png)
            url(images/ui-bg_glass_75_dadada_1x400.png)
            url(images/ui-bg_glass_75_e6e6e6_1x400.png)
            url(images/ui-bg_glass_95_fef1ec_1x400.png)
            url(images/ui-bg_highlight-soft_75_cccccc_1x100.png)
    
        *** Rewrite the icon images, that we use, to our local resources:
            url(images/ui-icons_222222_256x240.png)
            becomes
            url("' + GM_getResourceURL ("IconSet1") + '")
            etc.
    */
    var iconSet1    = GM_getResourceURL ("IconSet1");
    var iconSet2    = GM_getResourceURL ("IconSet2");
    var jqUI_CssSrc = GM_getResourceText ("jqUI_CSS");
    jqUI_CssSrc     = jqUI_CssSrc.replace (/url\(images\/ui\-bg_.*00\.png\)/g, "");
    jqUI_CssSrc     = jqUI_CssSrc.replace (/images\/ui-icons_222222_256x240\.png/g, iconSet1);
    jqUI_CssSrc     = jqUI_CssSrc.replace (/images\/ui-icons_454545_256x240\.png/g, iconSet2);
    
    GM_addStyle (jqUI_CssSrc);
    
    //--- Add some custom style tweaks.
    GM_addStyle ( '                 \
        div.ui-widget-overlay {     \
            background: red;        \
            opacity:    0.6;        \
        }                           \
    ' );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first post. please be kind :) i'm trying to get picture
Can you clarify this please? public static void MyMethod() { var context= new MyModel.Entities();
I'm new to this kabeja package so please can some one provide code example
I'm kind of new to this so please bear with me... Let's say I
I'm kind of new to this site and programming in general, so please excuse
I'm kind of new here so please bear with me if this seems like
I'm kind of new to this so please bear with me. I have a
im kind a new in this mod rewrite thing. im trying to do some
I'm fairly new to this so please go easy on me if this is
I'm really new to programming, so I'm having trouble explaining this -- please forgive.

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.