Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post How to display a particular div from viewsource

    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>

  • #2
    New Coder
    Join Date
    Mar 2009
    Posts
    74
    Thanks
    3
    Thanked 3 Times in 3 Posts
    You could try something like:

    Code:
    <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')


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •