Display Function Output Within An Anonymous Function
I am trying to output the SELECTED TEXT within my javascript code. I created a function that will get the selected text and I just want to output it when the submit button was outp
Solution 1:
Your getSelectionHtml()
function gets the text selected on a page, but I think you want the text selected in the tinymce editor.
Try:
editor.insertContent(
'[tooltip class="' + e.data.listboxClassName
+ '" title="' + e.data.textboxtooltipName + '"]'
+ editor.selection.getContent()
+ '[/tooltip]');
Solution 2:
Try
functiongetSelectionHtml() {
html = ""; // removed var so that it can be accessed globally.if (typeofwindow.getSelection != "undefined") {
var sel = window.getSelection();
if (sel.rangeCount) {
var container = document.createElement("div");
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents());
}
html = container.innerHTML;
}
} elseif (typeofdocument.selection != "undefined") {
if (document.selection.type == "Text") {
html = document.selection.createRange().htmlText;
}
}
//document.write(html); this will rewrite the document - don't do this!
}
and in the anonnymous function:
onsubmit: function( e )
{
getSelectionHtml(); // get selected the textif(html) // check whether text is selected
editor.insertContent( '[tooltip class="' + e.data.listboxClassName + '" title="' + e.data.textboxtooltipName + '"]'+ html+' [/tooltip]'); // html now reffers to the global variable
}
Post a Comment for "Display Function Output Within An Anonymous Function"