2011-08-22 49 views
1

触发器在FF文本框按键计数器定制警告这是我的警报功能可以显示警报消息:使用Javascript XUL

function alertPopup() { 
    var image = "file://C:/stat.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 in the Status-bar', false,]; 

document.getElementById('myImage').setAttribute("hidden", "false"); 

} 

这个函式,以获得在Firefox浏览器和粘贴输入的文本在文本框插件中。

onKeypress : function (e) { 
      var node = e.target; 
      var nodeName = node.nodeName.toLowerCase(); 
      //text area cache onKeyPress code 
      if (nodeName == "textarea" && node.value == "" && e.keyCode == 13) { 
      pde.fillText(node); 
      return; 
      } 
      // this node is a WYSIWYG editor or an editable node? 
      if ((nodeName != "html" || node.ownerDocument.designMode != "on") && node.contentEditable != "true") 
      return; 

      if (node.textContent == "" && e.keyCode == 13) { 
      pde.fillText(node); 
      return; 
      } 

      if (!node.tacacheOnSave) { 
      pde.fillText(node); 
      } 

     }, 
     onChange : function (e) { 
      var node = e.target; 
      var nodeName = node.nodeName.toLowerCase(); 
      //alert("onChange : "+nodeName); 
      if (nodeName != "textarea") 
      return; 
      pde.fillText(node); 
     }, 
     onInput : function (e) { 
      var node = e.target; 
      var nodeName = node.nodeName.toLowerCase(); 
      //alert("onInput : "+nodeName); 
      // Only for textarea node 
      if (node.nodeName.toLowerCase() != "textarea") 
      return; 

      if (node.value == "") 
      return; 
      pde.fillText(node); 
     }, 
     fillText : function (node) { 
      nodeSRC = node; 
      if (node.nodeName.toLowerCase() == "textarea") { 
      userContent = node.value; 
      } 
      else if (node.nodeName.toLowerCase() == "html") { 
      userContent = node.ownerDocument.body.innerHTML; 
      } 
      else // element.contentEditable == true 
      userContent = node.innerHTML; 
     }, 
     emptyNodeSRC : function (node){ 
      if (node.nodeName.toLowerCase() == "textarea") { 
      node.value = ""; 
      } 
      else if (node.nodeName.toLowerCase() == "html") { 
      node.ownerDocument.body.innerHTML = ""; 
      } 
      else // element.contentEditable == true 
      node.innerHTML = ""; 
     }, 

maxTextEntered:20;我想将这个参数添加到我的上面的代码。

如果用户在我的代码中的FF浏览器文本框中输入了超过20个chaserstrs,并且我想重置5分钟后的时间并重新开始计算,那么我如何触发弹出功能?

https://developer.mozilla.org/en/NsIAlertsService https://developer.mozilla.org/en/Code_snippets/Alerts_and_Notifications从这些链接中,我找不到任何脚本来满足我的要求。

请对我很好的解决了我的问题。 谢谢你们。

回答

1

5天后,我有解决我的问题。

的实际代码缓存userContent(即如果有的话,用户键入的东西在FF浏览器文本框或文本区域时),一切都将被放入缓冲存储器 &这将被保存,直到用户关闭现有案文 - 区域或文本框。 如果用户打开了一个新的文本框或一个新的文本区域&类型的东西,新userContent将被存储在缓冲区memeory(旧缓冲区将被删除)。

的想法是我的问题非常简单(我不能深想在一开始):

功能onkeypress事件功能:

if ((nodeName != "html" || node.ownerDocument.designMode != "on") && node.contentEditable != "true") // this tells it's a html text-box area// 
       return; 

      if (node.textContent == "" && e.keyCode == 13) { 
       pdes.fillText(node); 
       return; 
      } 

这告诉浏览器来检测用户输入内容并将其传递给fillText(节点)。这叫我的其他功能 fillText : function (node) to fill the values(texts)

要检查userContent variabel的值长度触发警报我如果用户达到指定数值。

 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"); 
} 

下面是完整的代码:

onKeypress : function (e) { 


      var node = e.target; 
      var nodeName = node.nodeName.toLowerCase(); 
      //text area cache onKeyPress code 
      //alert('hi1'); 


      if (nodeName == "textarea" && node.value == "" && e.keyCode == 13) { 

       pde.fillText(node); 

       return; 
      } 


      // this node is a WYSIWYG editor or an editable node? 
      if ((nodeName != "html" || node.ownerDocument.designMode != "on") && node.contentEditable != "true") 
       return; 

      if (node.textContent == "" && 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; 
     } 

注: 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.