Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

View and Copy Source Code of a Particular DIV Layer

Posted on 2010-11-24
3
Medium Priority
?
424 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

773 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