views:

42

answers:

2

Currently I am writing a system for a user that on filling in a form it creates a template for a HTML email that will be able to use with their CRM system, the issue is that you user is a bit docile and for the live of them cannot understand how to view the source of the page so they can copy and paste the template code into their CRM, what I am wanting is there to be able to have a link/button that user can click that will show the source code in a window, I am in now way a javascript developer so any tips, hints examples would be great.

A: 

I think the best practice here isn't really to use a Javascript trick, but to copy the HTML template into a visible section and replace "<" with "&lt;", ">" with "&gt;" (escaping other bits as needed).

I would argue that it makes for poor usability to force a user to view the page source themselves, and it's not hard to use regex to make these replacements.

Eric Wendelin
+1  A: 
Pointy
That works great is there any way I can strip out the javascript that shows in the source? And also the input button I use to call the code you wrote above.
sea_1987
Well if there's Javascript mixed in with the source you want to show - or, really, *anything* that you want to hide - then things get somewhat trickier. I'll ammend my answer to show you you can hide script elements. (I have to wonder what script blocks would be doing in the middle of your HTML email template, however.)
Pointy
it is not in the middle of the HTML it is in the head, that holds vital CSS to the template working in their CRM. Hence why I need to remove it, thanks for your help.
sea_1987