javascript - Identify whether the selected text in a web page is bold nor not -
I'm trying to identify whether a selected text (in Firefox) is bold or not? For example:
& lt; P & gt; Some & lt; B & gt; Text is typed & lt; / B & gt; Here & lt; / P & gt; & Lt; P & gt; Some & lt; Span style = "font-weight: bold" & gt; More text is typed & lt; / Span & gt; Here & lt; / P & gt;
The user can either choose a part of bold text or full bold text. Here's what I'm trying to do:
is the function selection () {var r = window.get selection (). GetRangeAt (0); // Then what? }
Can you help me?
Thank you - Srikanth
If editing is within an editable element or document , Then it's easy:
function selection iSBold () {var isBold = false; If (document.queryCommandState) {isBold = document.queryCommandState ("bold"); } The return is bold; Otherwise, it is a bit trickier: In non-IE browsers, you need to temporarily make the document editable: function selectionIsbold () {Var range, isBold = false; If (window.getSelection) {var sel = window.getSelection (); If (SL & amp; Cell.SGetRenzat & amp; CellCountCancount) {range = sel.getRangeAt (0); Document.designMode = "on"; Sel.removeAllRanges (); Sel.addRange (range); }} If (document.queryCommandState) {isBold = document.queryCommandState ("bold"); } If (document.designMode == "on") {document.designMode = "off"; } The return is bold; }
Comments
Post a Comment