1

I have question about cross-browser compatibility.

I want to use the event.target instead of event.srcElement in the following code to make it work for firefox.

I have used target = event.target || event.srcElement. It is not working. Any help will be appreciated.

function jumptoPopupMenuItem(theMenuID) 
{                
  if (event.srcElement.className == "RightClickMenuItems") 
  {
    if (event.srcElement.getAttribute("url") != null)
    {        
      var strParameters = "";                                    
      if (theMenuID == "mnuAppointmentMenu")
      {
        strParameters = "AppointmentNumber=" + m_strAppointmentTypeYearNumber;
      }
      else if (theMenuID == "mnuAvailableHourMenu")
      {
        strParameters = "PreFillLanguageID=" + m_nLanguageID;
        strParameters = strParameters + "&PreFillInterpreterID=" + m_nInterpreterID;
        strParameters = strParameters + "&PreFillDateOfService=" + m_dtDateOfService;
      }
      if (event.srcElement.getAttribute("target") != null)
      {
        var PopupWindow = window.open(
            event.srcElement.url + strParameters, 
            event.srcElement.getAttribute("target"));
        PopupWindow.focus();
      }
      else
      {
        window.location = event.srcElement.url;
      }
    }
    hidePopupMenu(theMenuID);
  }
}
Tom
  • 3,009
  • 1
  • 18
  • 23
user1678742
  • 153
  • 1
  • 7
  • 1
    This doesn't look like jQuery to me. Shouldn't this be tagged as *just* JavaScript instead? Also **It is not working** is extremely vague. Please help us to help you by including more details about *what* exactly isn't working; do you see any errors in the console? What behaviour do you expect? What behaviour do you get? – Matt Sep 18 '12 at 00:05
  • The code you've shown doesn't use the `target = event.target || event.srcElement` construct. It would help if you showed how you tried to use it, rather than showing your function without it. (Are you saying the function as shown works in IE, but incorporating the extra line breaks it?) – nnnnnn Sep 18 '12 at 05:54
  • Look here: http://stackoverflow.com/questions/7457260/event-target-not-working-on-firefox – Ilia Frenkel Sep 18 '12 at 06:02

1 Answers1

1

if you're using jquery, just use var $target = $(e.target); -- it'll do the right thing for the browsers.

chovy
  • 72,281
  • 52
  • 227
  • 295