Showing a demo of my CSS on any website


Tags: javascript,jquery,html,css

Problem :

I have developed a small component which can be put in to any website. Now, I want to develop a code that could demonstrate how would my component look like on any website.

So, the person would come to my page and put in his URL and then my code should embed my custom JS/CSS in to the downloaded HTML and display it. Something like this.

Here, like the feedback tab, I want to show my component any where on that page.



Solution :

In the example you linked, they are requesting the page specified in the url querystring parameter on the server, and then doing more or less the following steps:

  1. In the <head> tag they are adding a <base href="url" /> tag to the document. The base tag will make any relative links in the document treat the value in the href attribute as their root. This is how they are getting around broken css / images. (The base tag is supported by all browsers)
  2. At the end of the document (IE the </body> tag) they are injecting the javascript that runs their demos.
  3. They serve the modified HTML requested to the browser.

All of this is pretty straight forward in implementation. You could use regular expressions to match the <head> and </body> tags for steps 1 and 2 respectively. Depending on the server platform how you actually request the page will vary, but here are some links to get you started:


    CSS Howto..

    How can I rotate(or change) background image using CSS and Javascript

    How to Make CSS Property Apply to Everything Within Bootstrap Navbar?

    how to programmatically call the “click” of css

    How to toggle between display:none and display:block

    how to change the position of these links within div header

    How to make Zig Zag borders using CSS? [closed]

    How to change placeholder color in css

    How to limit a transform scale to the width and height of the parent element in CSS?

    css - jquery - how to remove wrapper div element?

    Rich HTML emails in Outlook 2007 and 2010… how do you remove the top margin?

    How do I detect that facebook app is loading page to change CSS?

    How to center a div tag in a html page without being affected by zooming

    How to create circle image and text Which are complementary to each other in bootstrap or pure css?

    How to position a div differently for a specific page?

    how to check what css code is invalid using browser plugins [closed]

    how do i change the css property for only one row with a custom class with out removing the styles from the other rows?

    How to expand sidebars sub-menu to the correct size?

    How to let users have the latest non cached code?

    How to set background image to keep its position while browser width is changing?

    Using CSS to show gradient as well as an image

    How to align stacked Font-Awesome icons correctly

    unexpected script/css conflict, how to resolve?

    How to insert HTML symbol after Bootstrap panel-heading in CSS?

    how to add line break in HTML using jQuery

    how do i place text opposite to Anchor Tag Using CSS [closed]

    How do I show a handle to indicate to the user that a panel is resizable?

    How to render a template with dynamic CSS?

    How to select an html element that has two class names?

    CSS stacking order - how to get this right?

    css/html, how to scale and center a logo image