Solved

View and Copy Source Code of a Particular DIV Layer

Posted on 2010-11-24
3
416 Views
Last Modified: 2012-06-21
Hi Experts

I am trying to build a basic function really. Well it can become complicated i dont know but i have seen it working elsewhere on a website (unfortunately cant remember now).

Basically i have a template.php page which has the following sample code

<div id="template">
<h1>Template Name</h1>
<p>Template Content</p>
</div>

Open in new window


Now users see the content but what i want them to be able to do is click a button labelled "copy source code". This will basically copy the content of the div "template" including the HTML tags. The idea is so that they can then paste the CODE in their own coding environments etc.

 I have no idea how to go about this, i have explored jQuery but not too sure. Any ideas or pointers will be GREATLY appreciated  
0
Comment
Question by:ACEAFTY
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
DVation191 earned 500 total points
Comment Utility
In IE, this is pretty easy:
function copyToClipboard(s) {
    if (window.clipboardData && clipboardData.setData) {
        clipboardData.setData('text', s);
    }
}


The difficulty in this is making it cross browser.
Details here:
http://www.deluxeblogtips.com/2010/06/javascript-copy-to-clipboard.html
0
 
LVL 1

Author Comment

by:ACEAFTY
Comment Utility
Hi DVation191

Thanks for your response this is definitly something that im looking for esp. zero clipboard. Just want to make sure of one thing if you can answer thats fine.

The HTML that the user see's on template.php is rendered html. Will Zero Clipboard copy the content of the DIV Layer including the HTML tags?

Thanks anyhow for pointing me in the right direction
0
 
LVL 20

Expert Comment

by:DVation191
Comment Utility
Zero Clipboard will grab everything within the <pre> tags, code and all, even if it's rendered HTML from PHP.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now