Проблема с Javascript, которая работает в IE, а не в Firefox - PullRequest
0 голосов
/ 14 мая 2010

У меня проблема с веб-страницей, которая работает в IE, но не в Firefox. Отладчик Firefox останавливается на следующей строке:

btnhelp = new button("btnhelp", framemenu.document.imghelp, "../images/gui/help_o.jpg", "../images/gui/help.jpg", "", "hand", true);

Я вижу, что кнопка определена в другом классе с некоторыми функциями-прототипами так:

function button(jscriptname, htmlobj, dnimg, dimimg, action, cursor, enabled, hlimg)
{
  //object for managing buttons easily
  this.img = htmlobj;

  if(htmlobj.name)
    this.name = htmlobj.name
  else if(htmlobj.id)
    this.name = htmlobj.id
  else
    this.name = "error";

  this.upimg = new Image();
  this.dnimg = new Image();
  this.dimimg = new Image();
  this.hlimg = new Image();

  this.upimg.src = this.img.src;
  this.dnimg.src = dnimg;
  this.dimimg.src = dimimg;
  if(hlimg)
    this.hlimg.src = hlimg;
  this.action = action;
  this.jscriptname = jscriptname;

  if(cursor)
    this.cursor = cursor;
  else
    this.cursor = "hand";

  if(enabled)
    this.enable();
  else
    this.disable();

  this.img.onclick= new Function(this.jscriptname + ".click();");
  this.img.onmouseover= new Function(this.jscriptname + ".mouseover();");
  this.img.onmouseout= new Function(this.jscriptname + ".mouseout();");
}

button.prototype.enable = _enable;
button.prototype.disable = _disable;
button.prototype.mouseover = _mouseover;
button.prototype.mouseout = _mouseout;
button.prototype.click = _click;
button.prototype.hilight = _hilight;

function _enable()
{
    this.img.src = this.upimg.src;
    this.img.style.cursor = this.cursor;
    this.enabled = true;    
}

function _disable()
{
    this.img.src = this.dimimg.src;
    this.img.style.cursor = "default";  
    this.enabled = false;
}

function _hilight(bool)
{
    this.img.src = this.hlimg.src;  
    this.enabled = bool;
}

function _mouseover()
{
    if(this.enabled)
        this.img.src = this.dnimg.src;
}

function _mouseout()
{
    if(this.enabled)
    {
        this.img.src = this.upimg.src;
    }
}

function _click()
{
    if(this.enabled)
        eval(this.action);

}

Когда отладчик нажимает на строку кнопки bthhelp = new, он переходит к nsSessionStore.js:

  handleEvent: function sss_handleEvent(aEvent) {

Как только он выходит из этой функции, он не возвращается к JavaScript, и следующая строка никогда не вызывается, что наводит меня на мысль, что в вызове есть проблема с созданием новой кнопки. Кто-нибудь знает, что мне нужно сделать, чтобы это исправить?

1 Ответ

3 голосов
/ 14 мая 2010

Если Firefox останавливается на линии

btnhelp = new button("btnhelp", framemenu.document.imghelp, "../images/gui/help_o.jpg", "../images/gui/help.jpg", "", "hand", true);

Единственными потенциальными проблемами могут быть либо button, либо он еще не определен, либо проблема с framemenu.document.imghelp. Все остальные аргументы являются примитивами, поэтому я не понимаю, почему возникнет проблема с любым из них.

Я бы предположил - это примерно столько, сколько кто-либо мог бы дать вам без дополнительной информации - что проблема в том, что framemenu - это идентификатор элемента в вашем документе, но на самом деле он не определен как переменная. Internet Explorer автоматически регистрирует все элементы с действительным атрибутом id как глобальные переменные, к которым можно получить доступ из скрипта без использования document.getElementById(). Ни один другой браузер не делает этого, вы должны использовать document.getElementById() или какую-либо другую форму выбора элементов.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...