| | |
Display html tags on a webpage
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Untitled Page</title> <script type="text/javascript"> function firstMethod() { var str = document.getElementById("tbl").innerHTML.replace(/[<]/g,'<'); str = str.replace(/[>]/g,'>'); document.getElementById("displayHTML").innerHTML = str; } function secondMethod() { document.getElementById("displayHTML").innerText = document.getElementById("tbl").innerHTML; } </script> </head> <body> <div id="displayHTML"></div> <table border="1" id="tbl"> <tr> <td style="width: 100px"> 1</td> <td style="width: 100px"> 2</td> <td style="width: 100px"> 3</td> </tr> <tr> <td style="width: 100px"> 4</td> <td style="width: 100px"> 5</td> <td style="width: 100px"> 6</td> </tr> <tr> <td style="width: 100px"> 7</td> <td style="width: 100px"> 8</td> <td style="width: 100px"> 9</td> </tr> </table> <input type="button" value="use conventional method" onclick="firstMethod()" /> <input type="button" value="use serkan's method" onclick="secondMethod()" /> </body> </html> This is a good example of using javascript innerText property which is not as popular as innerHTML property.
0
•
•
•
•
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
# This is a good example of using javascript innerText property which is not # as popular as innerHTML property
Yeah, good old sanity method, -not supported by crippled "modern" browsers until yesterday!
In fact, firefox still dosn't - currently tested in fx 3.5.3 no error but no go either...
Last edited by Troy III; Sep 19th, 2009 at 10:45 pm.
0
•
•
•
•
How "what?"!!!
Your precious:
"SERKAN's METHOD" type of think - will NOT work in Fire-Fox and other Netscape lurking children of the internet.
- What "what" ?
Your precious:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<input type="button" value="use serkan's method" onclick="secondMethod()" />
- What "what" ?
Last edited by Troy III; Sep 20th, 2009 at 3:43 am.
0
•
•
•
•
if it does not work in those browsers, just find the substitute and post it to here instead of useless commenting.
1
•
•
•
•
Something like this should work:
Example:
It replaces every non-alphabetic and numeric character (excluding a few defined in the regex pattern) with their character codes.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
/** * Return html numeric entities encoded string */ String.prototype.toHtmlEntities = function() { return this.replace(/[^a-z0-9\.\-\_\s\t]/ig, function(c) { return '&#'+c.charCodeAt(0)+';'; }); };
Example:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
'<div>This & that</div>'.toHtmlEntities();
It replaces every non-alphabetic and numeric character (excluding a few defined in the regex pattern) with their character codes.
Similar Threads
- I need to extract specific html tag data from html webpage using java (Java)
- Get an html tags name or id attribute? (PHP)
- html tags (PHP)
- PHP tags into HTML tags (PHP)
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxexample ajaxjspservlets array autoplay blackjack browser captcha captchaformproblem cart child class close codes date debugger dependent developer disablefirebug dom editor element embed engine enter events explorer ext file firefox flash form forms frameworks game gears getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe java javascript javascripthelp2020 jquery jsf jsp jump libcurl maps margin marquee masterpage math media menu object onerror onmouseoutdivproblem onreadystatechange parent passing paypal pdf php player position post programming prototype rated redirect safari scale scriptlets scroll search security size software solutions sources star stars stretch synchronous toggle tweet unicode variables web webkit webservice window \n



