Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

2009/07/01

Permission denied to get property HTMLDivElement.parentNode

pForm is cool, and I just used it to build a form yesterday. But it worked fine yesterday, but this morning, when I when tried to select the date from Date field, I got this error message:

Permission denied to get property HTMLDivElement.parentNode

pForm integrated the calendar.js developed by Dynarch.com, seems this is a bug of firefox . Here is a quick fix. Open calendar.js at line 131 in the code. Add try and catch like below,

Calendar.isRelated = function (el, evt) {
   var related = evt.relatedTarget;try{
   if (!related) {
      var type = evt.type;
      if (type == "mouseover") {
         related = evt.fromElement;
      } else if (type == "mouseout") {
         related = evt.toElement;
      }
   }
   while (related) {
      if (related == el) {
         return true;
      }
      related = related.parentNode;
   }
   return false;
   }catch(e){
      return;
   }
};

2009/06/24

escape single quote in javascript

Problem:

alias_term = trim(alias_term);
var str = '<a href="javascript:updt_mapping(\'alias\',\''+alias_term+'\');">Update Alias</a>';
Using above code, when the alias_term is something like k’nex, which has single quote, it would broke the javascript, for the javascript statement become updt_mapping(‘alias’, ‘k’net’)

Solution:

escape single quote, but you could not using escape function, alias_term = escape(alias_term), but replace function, alias_term = alias_term.replace(/\'/,"\\'");