Solved

View and Copy Source Code of a Particular DIV Layer

Posted on 2010-11-24
3
417 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
ID: 34205228
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
ID: 34205453
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
ID: 34205872
Zero Clipboard will grab everything within the <pre> tags, code and all, even if it's rendered HTML from PHP.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

11 Experts available now in Live!

Get 1:1 Help Now