Вот наваял для вас примерчик. Только имейте в виду, что таким образом можно узнать, что текст жирный, только в том случае, если он обрамлен в теги <strong></strong> или <b></b>. Но если использован CSS придется «извращаться» сильнее. Итак, вот основной документ с кнопкой B: | Код | <!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>
<meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>Template</title>
<style type="text/css"> #btnB { background: #ECE9D8; border: 3px solid; border-bottom-color: #808080; border-left-color: #FFFFFF; border-right-color: #808080; border-top-color: #FFFFFF; color: #000000; font-size: 20pt; font-weight: bold; text-align: center; width: 30px; } </style>
<script type="text/javascript"> function isStrong() { var _result = false; var parentEl = null; var sel = null; var ifrWnd = document.getElementById("ifrm").contentWindow; if (ifrWnd.getSelection) { sel = ifrWnd.getSelection(); parentEl = sel.anchorNode.parentNode; } else { sel = ifrWnd.document.selection; parentEl = (sel.createRange()).parentElement(); } while (parentEl != null) { if ((parentEl.nodeName.toLowerCase() == "strong") || (parentEl.nodeName.toLowerCase() == "b")) { _result = true; break; } else { parentEl = parentEl.parentNode; } } return _result; } function sayIfStrong(evnt) { var buttonBold = document.getElementById("btnB"); if (buttonBold == null) return true; if (isStrong()) { with (buttonBold.style) { borderTopColor = "#808008"; borderRightColor = "#FFFFFF"; borderBottomColor = "#FFFFFF"; borderLeftColor = "#808080"; } } else { with (buttonBold.style) { borderTopColor = "#FFFFFF"; borderRightColor = "#808080"; borderBottomColor = "#808080"; borderLeftColor = "#FFFFFF"; } } }
function turnOnDM() { document.getElementById("ifrm").contentWindow.document.designMode = "on"; var ifrWnd = document.getElementById("ifrm").contentWindow; if (ifrWnd.addEventListener) { ifrWnd.addEventListener("mouseup", sayIfStrong, false); } else { ifrWnd.document.attachEvent("onmouseup", sayIfStrong); } } window.onload = turnOnDM; </script> </head>
<body> <div id="btnB">B</div> <p><iframe src="iframe_doc.htm" id="ifrm" height="400" width="500"></iframe></p> </body>
</html> |
А это документ, загруженный в iframe (iframe_doc.htm): | Код | <!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> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>Template</title> </head> <body> <p>Lorem ipsum <b>dolor sit amet, consectetur adipiscing</b> elit. Proin accumsan adipiscing magna. Sed et nulla.</p> <p>Cras fermentum vulputate metus. Nam vulputate. <strong>Donec interdum auctor ante. <span style="color: red;">Curabitur facilisis malesuada tellus.</span></strong></p> <p>Mauris rutrum, elit ut interdum mattis, sapien nulla lobortis ipsum, ut sagittis felis massa pretium ipsum. <b>In massa erat, scelerisque in, interdum sed, pretium ut, erat. <u>Duis congue.</u></b> Nunc consectetur, nibh in blandit tincidunt, augue lectus ullamcorper magna, non sodales risus felis nec ligula.</p> <p><strong>Sed pede.</strong> Integer tincidunt posuere tellus.</p> </body> </html>
|
|