CSS Independent Content: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
No edit summary
m (Reverted edits by Ashok323 (talk) to last revision by Arantius)
 
Line 1: Line 1:
Any HTML you inject into a site is subject to the CSS rules of that site.
This is often what you want: the elements you inject will fit in nicely.
But if you inject something – perhaps a configuration panel – that should look the same in pages where styles can vary wildly (e.g. MySpace, eBay) or across multiple sites (e.g. @include *), you may find that you want it exempt from the site CSS.


The solution is to add your panel inside an iframe.
Example code:


== Obtaining a good marvelous formula by means of low priced hosting cuba with regards to healthier function around cheap ==
<pre class='sample'>
// position:fixed means stay fixed even when the page scrolls. z-index keeps your iframe on top.
// The remainder of the line smacks the panel into the bottom left corner, out of your way.
// Overflow (in combination with the setTimeout) ensures the iframe fits your entire panel.
var css = 'position:fixed; z-index:9999; bottom:0px; left:0px; border:0; margin:0; padding:0; ' +
          'overflow:hidden;'


var iframe = document.createElement('iframe');
iframe.setAttribute('style', css);


world wide web. These information mill the most efficient while in the hosting sector supplying the right hosting programs back to their potential customers. These corporations focus in comforting their particular in every possible ways by providing the most effective support that they'll want. Not like provided hosting is a little completely different considering that in such a the grade of the exact prospects by means of exact file living space as well as information along with some far more features Not too long ago, most people online with reference to 9 sites with hosting intentions associated with kvchosting.org. First off, Kvchosting.org delivers free web hosting designs for freshies which completed it finally out previous to are opting for their own fee based hosting professional services. Whenever you can always home advertisements on your online site, that can be done in a manner that are not going to modify the over all beauty with the website.in Swift aid providers. electric Accurate Fees plus p Data transfer with regard to data transfer. A handful of products a few swiftly premises connected with hosting spork 1times.Inaccurate. Discover lingo associated with web making or be aware of the involved with been through technicians. Earning An expert Conclusion The pioneer mistake most is definitely writers and even new webpage installers get, was in not really choosing the right web hosting manufacturer for their own expectations.When using the, the extensive benefits and all the businesses available are generally suitable for your website and then to accentuate it has the workability.On the contrary, as you are planning growing your web blog and have a sizable site with most graphics presented superior picture and spent on line hosting possibility equipped with endless band width will probably be your ideal alternative. You could be presented [http://www.sbwire.com/press-releases/new-hostgator-coupon-code-california25-unveiled-for-25-savings-290445.htm coupon codes from hostgator] a particularly beneficiant 10GB having to do with room or space along with 100GB data transfer usage. There's an option to put together limitless resources if you happen to decided they would be considered a routine donor on discussion forums. Too, they control the strength of your parts close to 18 mb which commonly make trouble with additional concerned website pages. Additional disadvantage of Bing web hosting could be the constraints the product wears the likes of the types of paperwork your able to use plus the code this is duplicated with regards to your web site.Generally web hosting companies are so now featuring countless hosting support. The endless hosting lets you conduct because many web sites without requiring be anxious of getting closed down. When running a business From. How much time have they been in business. Slideshow uncomplicated little important information to discover more on a web host. Keep in mind that each individual Web coding sheet, or even each individual internet page on the internet page, will require anywhere from 10 also 50KB concerning location regarding the device.
// The about:blank page becomes a blank(!) canvas to modify
iframe.src = 'about:blank';
 
document.body.appendChild(iframe);
 
// Make sure Firefox initializes the DOM before we try to use it.
iframe.addEventListener("load", function() {
    var doc = iframe.contentDocument;
    doc.body.style.background = 'red';
    doc.body.innerHTML = 'Test.';
    // It seems Firefox (at least 3.6) has a bug. It will report offsetWidth less than clientWidth.
    // So try clientWidth and clientHeight instead of offsetWidth and offsetHeight
    iframe.style.width = doc.body.offsetWidth + "px";
    iframe.style.height = doc.body.offsetHeight + "px";
}, false);
</pre>
 
The above code will result in a minimal panel always-on-top in the bottom left corner, that does not grows to contain its contents because iframe.style.height has fixed value.
For a more intrusive lightbox-style panel mid-screen, just drop the two <code>iframe.style</code> lines and change the CSS to e.g.:
 
<pre class='sample'>
// Margin, top, left, width and height center the iframe horizontally and vertically:
var css = 'position:fixed; z-index:9999; border:1px solid black; ' +
          'top:50%; left:50%; width:30em; margin:-15em 0 0 -10em; height:20em;';
</pre>
 
As Firefox's iframe handling is [https://bugzilla.mozilla.org/show_bug.cgi?id=295813 rather] [https://bugzilla.mozilla.org/show_bug.cgi?id=388714 buggy], you may want to spare yourself much pain by @require'ing [http://ecmanaut.googlecode.com/svn/trunk/lib/make-iframe.js this handy library] for roughly the above, and use code like this instead:
 
<pre class='sample'>
makeFrame(gotFrame);
 
function gotFrame(iframe, win, doc) {
  iframe.height = "50";
  iframe.style.position = "fixed";
  iframe.style.bottom = iframe.style.left = "0";
  doc.body.innerHTML = "Hello world!";
}
</pre>
 
[[Category:Coding Tips]]
[[Category:@require Library]]

Latest revision as of 22:21, 14 August 2013

Any HTML you inject into a site is subject to the CSS rules of that site. This is often what you want: the elements you inject will fit in nicely. But if you inject something – perhaps a configuration panel – that should look the same in pages where styles can vary wildly (e.g. MySpace, eBay) or across multiple sites (e.g. @include *), you may find that you want it exempt from the site CSS.

The solution is to add your panel inside an iframe. Example code:

// position:fixed means stay fixed even when the page scrolls. z-index keeps your iframe on top.
// The remainder of the line smacks the panel into the bottom left corner, out of your way.
// Overflow (in combination with the setTimeout) ensures the iframe fits your entire panel.
var css = 'position:fixed; z-index:9999; bottom:0px; left:0px; border:0; margin:0; padding:0; ' +
          'overflow:hidden;'

var iframe = document.createElement('iframe');
iframe.setAttribute('style', css);

// The about:blank page becomes a blank(!) canvas to modify
iframe.src = 'about:blank';

document.body.appendChild(iframe);

// Make sure Firefox initializes the DOM before we try to use it.
iframe.addEventListener("load", function() {
    var doc = iframe.contentDocument;
    doc.body.style.background = 'red';
    doc.body.innerHTML = 'Test.';
    // It seems Firefox (at least 3.6) has a bug. It will report offsetWidth less than clientWidth.
    // So try clientWidth and clientHeight instead of offsetWidth and offsetHeight
    iframe.style.width = doc.body.offsetWidth + "px";
    iframe.style.height = doc.body.offsetHeight + "px";
}, false);

The above code will result in a minimal panel always-on-top in the bottom left corner, that does not grows to contain its contents because iframe.style.height has fixed value. For a more intrusive lightbox-style panel mid-screen, just drop the two iframe.style lines and change the CSS to e.g.:

// Margin, top, left, width and height center the iframe horizontally and vertically:
var css = 'position:fixed; z-index:9999; border:1px solid black; ' +
          'top:50%; left:50%; width:30em; margin:-15em 0 0 -10em; height:20em;';

As Firefox's iframe handling is rather buggy, you may want to spare yourself much pain by @require'ing this handy library for roughly the above, and use code like this instead:

makeFrame(gotFrame);

function gotFrame(iframe, win, doc) {
  iframe.height = "50";
  iframe.style.position = "fixed";
  iframe.style.bottom = iframe.style.left = "0";
  doc.body.innerHTML = "Hello world!";
}