Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After 5 days, I have a solution for my problem.</p> <p>The actual code buffers the userContent (i.e when ever if the user types something in FF browser text-box or text area) everything will be put in the buffer memory &amp; this will be stored until the user closes the present text-area or text-box. If the user opens up a new text-box or a new text-area &amp; types something the new userContent will be stored in the buffer memeory(the old buffer will be deleted).</p> <p>The idea is very simple for my problem(which i couldn't think deep in the beginning):</p> <p>The function onKeypress function:</p> <pre><code> if ( ( nodeName != "html" || node.ownerDocument.designMode != "on" ) &amp;&amp; node.contentEditable != "true" ) // this tells it's a html text-box area// return; if ( node.textContent == "" &amp;&amp; e.keyCode == 13 ) { pdes.fillText(node); return; } </code></pre> <p>This tells the browser to detect the user is typing something and pass it to the fillText(node). This call my other function <code>fillText : function (node) to fill the values(texts)</code>.</p> <p>To check value length of the userContent variabel to trigger my alert if the user reached the assigned number value.</p> <pre><code> else if ( node.nodeName.toLowerCase() == "html" ) // his tells it's a html text-box area of any website in FF browser// { userContent = node.ownerDocument.body.innerHTML; var myTest = userContent.length; if(userContent.length == 20) { alertPopup(); //calling my custom alert function. } function alertPopup() { var image = "chrome://PDE/skin/build.png"; var win = Components.classes['@mozilla.org/embedcomp/window-watcher;1']. getService(Components.interfaces.nsIWindowWatcher). openWindow(null, 'chrome://global/content/alerts/alert.xul', '_blank', 'chrome,titlebar=no,popup=yes', null); win.arguments = [image, 'Hi, there', 'You can make a PDE by clicking on the PDE button on the tool-bar', false]; //document.getElementById('myImage').setAttribute("hidden", "false"); } </code></pre> <p>Here is the full code:</p> <pre><code>onKeypress : function (e) { var node = e.target; var nodeName = node.nodeName.toLowerCase(); //text area cache onKeyPress code //alert('hi1'); if ( nodeName == "textarea" &amp;&amp; node.value == "" &amp;&amp; e.keyCode == 13 ) { pde.fillText(node); return; } // this node is a WYSIWYG editor or an editable node? if ( ( nodeName != "html" || node.ownerDocument.designMode != "on" ) &amp;&amp; node.contentEditable != "true" ) return; if ( node.textContent == "" &amp;&amp; e.keyCode == 13 ) { pde.fillText(node); return; } if (!node.tacacheOnSave) { pde.fillText(node); } }, fillText : function (node) { // declare tmpNodeVal OUTSIDE the function nodeSRC = node; var tmpNodeVal = ""; if ( node.nodeName.toLowerCase() == "textarea" ) { userContent = node.value; } else if ( node.nodeName.toLowerCase() == "html" ) { userContent = node.ownerDocument.body.innerHTML; //alert(userContent); var myTest = userContent.length; if(userContent.length == 50) { alertPopup();//calling my custom alert function. } else if(userContent.length == 200) { PopupNotifications.show(gBrowser.selectedBrowser, "PDES-popup", "Hi, there!, You have reached more than the max level !", "pde-toolbar-button", /* anchor ID */ { label: "Build PDES", accessKey: "D", callback: function() { if(nodeSRC!=null) pde.emptyNodeSRC(nodeSRC); window.openDialog("chrome://hello/content/hellouilder.xul", "hello", "chrome,width=400,height=360",userContent, nodeSRC); } },null, { timeout:1000}); } } else // element.contentEditable == true userContent = node.innerHTML; } </code></pre> <p>Note: <code>1. The above code covers the functionality of KeyPress counter and trigger an alert. With the above code, we can trigger an alert for the "Subject" area in Gmail or Yahoo websites during email writting process.</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload