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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:54:40+00:00 2026-06-01T14:54:40+00:00

I would like my chrome extension to be able to inject a 300px sidebar

  • 0

I would like my chrome extension to be able to inject a 300px sidebar on the right side of any page when it is activated. I am looking for the best way to constrain the entire page to document.body.clientWidth – 300, thereby leaving the 300px on the right for my sidebar. The sidebar I currently inject is appended to document.body and has a style like so:

width:300px
position: fixed
top: 0px
right: 0px
height:500px

I need a way to prevent the existing page elements from bleeding over into my sidebar. I was hoping that there would be a way to trick the existing elements into thinking that they were rendering into a browser client 300px narrower than their actual window thereby leaving space for my sidebar but I haven’t found any easy way to do so…

  • 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-01T14:54:41+00:00Added an answer on June 1, 2026 at 2:54 pm

    Update

    For anyone googling, overhauled this to reflect what I’m actually using in an app, use jQuery, have more safeguards, and be more respectful of current page css.

    //height of top bar, or width in your case
    var height = '30px';
    
    //resolve html tag, which is more dominant than <body>
      var html;
      if (document.documentElement) {
        html = $(document.documentElement); //just drop $ wrapper if no jQuery
      } else if (document.getElementsByTagName('html') && document.getElementsByTagName('html')[0]) {
        html = $(document.getElementsByTagName('html')[0]);
      } else if ($('html').length > -1) {//drop this branch if no jQuery
        html = $('html');
      } else {
        alert('no html tag retrieved...!');
        throw 'no html tag retrieved son.';
      }
    
    //position
    if (html.css('position') === 'static') { //or //or getComputedStyle(html).position
      html.css('position', 'relative');//or use .style or setAttribute
    }
    
    //top (or right, left, or bottom) offset
    var currentTop = html.css('top');//or getComputedStyle(html).top
    if (currentTop === 'auto') {
      currentTop = 0;
    } else {
      currentTop = parseFloat($('html').css('top')); //parseFloat removes any 'px' and returns a number type
    }
    html.css(
      'top',     //make sure we're -adding- to any existing values
      currentTop + parseFloat(height) + 'px'
    );
    

    You’re almost done. You’ve styled the page html. You might have noticed css from the page affects your stuff to. You can resolve this by containing it within an iframe:

    var iframeId = 'someSidebar';
    if (document.getElementById(iframeId)) {
      alert('id:' + iframeId + 'taken please dont use this id!');
      throw 'id:' + iframeId + 'taken please dont use this id!';
    }
    html.append(
      '<iframe id="'+iframeId+'" scrolling="no" frameborder="0" allowtransparency="false" '+
        'style="position: fixed; width: 100%;border:none;z-index: 2147483647; top: 0px;'+
               'height: '+height+';right: 0px;left: 0px;">'+
      '</iframe>'
    );
    document.getElementById(iframeId).contentDocument.body.innerHTML =
      '<style type="text/css">\
        html, body {          \
          height: '+height+'; \
          width: 100%;        \
          z-index: 2147483647;\
        }                     \
      </style>                \
      <p>UNSTYLED HTML!</p>';
    

    Yes, you have to append the iframe before setting the innerHTML

    You should be able to copy/paste and edit this and be one your way!

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

Sidebar

Related Questions

I would like to have a Google Chrome extension to rehost any image I
I'm writing a Chrome extension, and would like to be able to clean up
I would like to write a small Google Chrome extension in which I use
I am making a Google Chrome extension and I would like to have my
Using a Google Chrome Extension, I would like to fire some event or somehow
I would like to implement a Google Chrome extension to modify POST requests. In
I would like to create a chrome extension with GWT. Is it possible to
I would like that my Chrome extension title to be on the relevant language
I'd like to self host a chrome extension on my own site but would
I would like to write a google chrome extension to intercept http traffic and

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.