Sunday, April 8, 2012

Showing a demo of my CSS on any website

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.

Source: Tips4all


  1. Nathan's answer is the closest to how we have done the demo feature at WebEngage. To make such a demo functional, you'll need to create a Javascript widget that can be embedded on third party sites. syserr0r's answer on creating a bookmarklet is the simplest approach to do so. Our's is a JAVA backend and we use HttpClient to fetch the responses. As Nathan suggested, we parse the response, sanitize it and add our widget Javascript to the response. The widget JS code takes it on from there to render the Feedback tab and load a demo short survey.

    Disclosure: I am a co-founder and ceo at WebEngage.

  2. I recommend using bookmarklets. I've made a bookmarklet generator for adding jQuery-enabled bookmarklets to a page to make development easier.

    There's a caliper bookmarklet on the page that you can mess around with just to show an example of it working.

    Full disclosure, this is something I've made, I'm not trying to be spammy as I think it's relevant: zbooks

  3. You could make an iframe page, which loads their page in the iframe, and uses javascript to inject your code into the iframe.

  4. I had a problem of a similiar nature, and the main obstacle is the cross-domain policy.

    You have to ask the user to put your code in a <script src="..."> or create a proxy solution that would add your code for them.

    I went for the proxy and here are my observations:

    it's easy to create a basic proxy in php - there are some php proxies on sourceforge and Ben Alman has created a simple php proxy for AJAX. Based on those I was able to create a php proxy altering the content properly in one day.
    after that I spent a lot of time making it work with more and more sites with issues. You can never create a perfect proxy.

    As an alternative (sa long as you are non-commercial) you can use and put the site in an iframe and then do whatever you want to do with the iframes document, as it's in your domain thanks to the proxy. You can access iframeDOMnode.contentWindow.document then, etc.

  5. I agree with the bookmarklet strategy.

    I'm a fan of, which lets you generate bookmarklets easily, inject jQuery, etc.