Solved

View and Copy Source Code of a Particular DIV Layer

Posted on 2010-11-24
3
422 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

630 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