UIWebview with contenteditable - superscript and subscript NOT work
Just tested this page on my iOS7.1 iPad:
http://quirksmode.org/dom/execCommand/
Both superscript and subscript work. Looking at the source, the following command is performed: document.execCommand("superscript", false, null);
Show keyboard in contenteditable UIWebView programmatically
UIwebview is not editable and you can not make it first responder.
Where as you can use javascripts for that purpose , try out this answer
UIWebView with contentEditable (html editing), first responder handling?
contenteditable div in UiWebView - new lines are not saved when clicking on done
Perhaps this JSFiddle can shed some light onto what's happening within your application. If you type some lines in the top DIV (gray background color), the HTML code that you get as the return value of its innerHTML
property will first display in a textarea
field below it (including HTML tags formatting). As you will soon see it's not merely what you'd expect to handle in your application ('line one' + CRLF + 'line two'...), but it also contains HTML elements separating lines one from another. That's how browsers are able to display contenteditable
DIVs as if they're 'memo' type controls - by parsing their HTML (that's what browsers do). This HTML formatted text is also how your application receives user submitted text, and there you have to decide what to do with this formatting. You can either strip them away (which is, I suspect, how you set that object's property and it deals with that for you) replacing HTML elements like <DIV></DIV>
and so on with a space character, or choose (with your control's property, or in code) to handle this formatting whichever way you'd like them to be handled. I'm not familiar with UIWebView
though, and you'll have to find on your own how to retrieve complete HTML formatted values that you want to apply to the next DIV element that you're displaying (or same one that you're assigning new values to).
UPDATE: After searching the web for UIWebView
reference, I've actually stumbled across one related thread on SO that shows how to retrieve innerHTML value of an element in your underlying HTML document:
//where 'wView' is your UIWebView
NSString *webText = [wView stringByEvaluatingJavaScriptFromString:@"document.getElementById('inputDIV').innerHTML"];
This way you'd be able to retrieve the whole innerHTML
string contained within the contenteditable
DIV that you use in a webText
string variable and parse its HTML formatted text to whatever suits your needs better. Note though, that different browsers format contenteditable
DIVs differently when Enter Key
is pressed and some will return the next line enclosed in a new DIV
, while others might enclose it in paragraph P
and/or end the line with a break <BR>
or <BR />
, when shift
+enter
were used together to move to the next line. You will have to account for all these possibilities when processing your input string. Refer to the JSFiddle script I wrote using your UIWebView
component to check what formatting applies.
Of course, in your case, it might be simpler to replace your contenteditable
DIV with a textarea
that will return more commonly formatted \n
end-of-line (CR+LF). DIVs however are easier to design, so choose whichever suits your needs better.
Cheers!
contenteditable div in UiWebView - new lines are not saved when clicking on done
Perhaps this JSFiddle can shed some light onto what's happening within your application. If you type some lines in the top DIV (gray background color), the HTML code that you get as the return value of its innerHTML
property will first display in a textarea
field below it (including HTML tags formatting). As you will soon see it's not merely what you'd expect to handle in your application ('line one' + CRLF + 'line two'...), but it also contains HTML elements separating lines one from another. That's how browsers are able to display contenteditable
DIVs as if they're 'memo' type controls - by parsing their HTML (that's what browsers do). This HTML formatted text is also how your application receives user submitted text, and there you have to decide what to do with this formatting. You can either strip them away (which is, I suspect, how you set that object's property and it deals with that for you) replacing HTML elements like <DIV></DIV>
and so on with a space character, or choose (with your control's property, or in code) to handle this formatting whichever way you'd like them to be handled. I'm not familiar with UIWebView
though, and you'll have to find on your own how to retrieve complete HTML formatted values that you want to apply to the next DIV element that you're displaying (or same one that you're assigning new values to).
UPDATE: After searching the web for UIWebView
reference, I've actually stumbled across one related thread on SO that shows how to retrieve innerHTML value of an element in your underlying HTML document:
//where 'wView' is your UIWebView
NSString *webText = [wView stringByEvaluatingJavaScriptFromString:@"document.getElementById('inputDIV').innerHTML"];
This way you'd be able to retrieve the whole innerHTML
string contained within the contenteditable
DIV that you use in a webText
string variable and parse its HTML formatted text to whatever suits your needs better. Note though, that different browsers format contenteditable
DIVs differently when Enter Key
is pressed and some will return the next line enclosed in a new DIV
, while others might enclose it in paragraph P
and/or end the line with a break <BR>
or <BR />
, when shift
+enter
were used together to move to the next line. You will have to account for all these possibilities when processing your input string. Refer to the JSFiddle script I wrote using your UIWebView
component to check what formatting applies.
Of course, in your case, it might be simpler to replace your contenteditable
DIV with a textarea
that will return more commonly formatted \n
end-of-line (CR+LF). DIVs however are easier to design, so choose whichever suits your needs better.
Cheers!
Related Topics
How to Make The Web Page Height to Fit Screen Height
How to Force Inline Divs to Stay on Same Line
HTML Contenteditable with Non-Editable Islands
Which Dom Elements Can Be Child of Tr
Internet Explorer and Clip-Path
How to Make a Table with Equal Column Widths in CSS
Draw Triangle in Corner of Div
Bootstrap - Fill Fluid Container Between Header and Footer
CSS Prevent Div Flex from Stretching Child
How to Correctly Use "Scoped" Styles in Vuejs Single File Components
Chrome, Safari Ignoring Max-Width in Table
How to Show Three Columns Per Row
How to Hide Autofill Safari Icon in Input Field
Change The Color of Glyphicons to Blue in Some- But Not at All Places Using Bootstrap 2