...

View Full Version : How to display a particular div from viewsource



bala2111
09-26-2011, 01:01 PM
hey all,
Am trying to display the div tag and its content by clicking it. the code below displays the whole source code when cliked on the div with id = softros. I want to make this script to display the div in view source format of the browser when clicked on any div.

Thanks in advance, looking forward for your ideas

Regards,
Bala




<html>

<head>
<script>
function viewSource()
{

window.open('view-source:'+location.href);
}
</script>
</head>
<body>
<div id="softros" onClick="viewSource();" style="border:1px red solid;">
<img src="images/rain_small.jpg" alt="rain_small" title="rain_small" />
</div>
</body>
</html>

Raphael
09-26-2011, 04:23 PM
You could try something like:


<html>
<head>


<script language="javascript" type="text/javascript">

function escapeHTML(str)
{
return str.replace(/[&"<>]/g, function (m) "&" + ({"&": "amp", '"': "quot","<": "lt",">": "gt" })[m] + ";");
}

function viewSource(elid)
{
var ih=escapeHTML(document.getElementById(elid).innerHTML)



var w=window.open("") //open blank window and write to it
w.document.open() //open document stream
w.document.write('source of '+elid+':<br><br>')
w.document.write(ih)
w.document.close()
}
</script>
</head>

<body>

<div id="mydiv">
blah blah blah <a href="yay.html">yay</a> <span style="background-color:red;">woo</span>
</div>

</body>
</html>

and call:
viewSource('mydiv')



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum