Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Extension - Prevent CSS From Being Over Written

I am writing a Chrome Extension where a small panel appears on top of the existing website. When I go to certain websites, I notice that the CSS of my panel has been over-written by the website's CSS. I am currently using Eric Meyer's CSS Reset but it does not seem to be doing the trick. Is there something else I can do?

like image 507
Jon Avatar asked Apr 10 '12 23:04

Jon


1 Answers

Here's a nifty 'hack' with iframes, where you don't actually instantiate an iframe:

  1. Append an iframe to the DOM, this will be a container for your do dad
  2. Walk into the iframe and add your HTML code to the innerHTML of the body

It looks like this:

var iframe = document.createElement('iframe');
document.documentElement.appendChild(iframe); //fastest way to append to DOM: http://jsperf.com/insertbefore-vs-appendchild/2
iframe.contentDocument.body.innerHTML = '<a href="yomama.com">Normal link!!</a>';
like image 125
Devin Rhode Avatar answered Sep 22 '22 22:09

Devin Rhode