Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8318637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:02:41+00:00 2026-06-08T22:02:41+00:00

I am facing a cross browser issue while trying to pass an event object

  • 0

I am facing a cross browser issue while trying to pass an event object from an onclick event.

Currently, I am doing the following

for (var i = 0; i < list.length; i++)
{
  var link= list[i];     
  link.onclick = function(el) {  return function () {LinkManager.HandleOnClick(window.event, el); }}(link);
 }

Firefox doesn’t respect window.event. However, how else can I pass it?

I resorted to a "not" clean solution:

for (var i = 0; i < list.length; i++)
{
  var link= list[i];     
  link.onclick =  SomeClickHandler;
 }

function SomeClickHandler(e)
{
  e = e || window.event;
  if (typeof (e) !== 'undefined')
  {
    var element = e.target || e.srcElement;
    LinkManager.HandleOnClick(e, element);
  }
}

Can anyone recommend a better way of solving it? I really didn’t like the workaround that I did.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:02:42+00:00Added an answer on June 8, 2026 at 10:02 pm

    If I understand correctly, you want your handler to have access to the el variable and the event object when it’s called. That’s possible and not that hard, but you might want to read up on closures:

    link.onclick = (function(el)
    {
        return function (e)//this function will receive the event object
        {
            e = e || window.event;//for ie
            LinkManager.HandleOnClick(e, el);
        }
    })(link);
    

    but, to be honest, this is overkill, try this (pun intended):

    link.onclick = function(e)
    {//this refers to `link`, the clicked element
        e = e || window.event;//for ie
        LinkManager.HandleOnClick(e, this);
    };
    

    or even less code:

    link.onclick = function(e)
    {//this refers to `link`, the clicked element
        e = e || window.event;//for ie
        LinkManager.HandleOnClick.apply(this,[e]);
        //LinkManager.HandleOnClick will receive 1 argument, the event object, and 'this' will point to 'link'
    };
    

    and even less:

    link.onclick = LinkManager.HandleOnClick;//this === link, 1 argument: the event object
    

    That said, you’re iterating a list, and attaching an event listener to each individual child element. I’d strongly advise you to use delegaion:

    if (list.addEventListener)
    {
        list.addEventListener('click',LinkManager.HandleOnClick,false);
    }
    else if (list.attachEvent)
    {
        list.attachEvent('onclick',LinkManager.HandleOnClick);
    }
    else
    {
        //use the loop you have now as a last resort
    }
    
    //LinkManager.HandleOnClick should start like so:
    LinkManager.HandleOnClick = function(e)
    {
        e = e || window.event;//<- you have the event object here
        var target = e.target || e.srcElement;//=== list item: your link variables, your element
        console.log(this);//<-should reference the list element (<ul> || <ol>)
    };
    

    Anyway, that’s how I’d tackle this

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm facing the same issue, while trying for cross-domain request. Situation is strange, my
Facing some issue in Talend Admin Console, the jobs that are running from IDE
issue facing while loading the messages in to mq channel, recieving an error like
facing the issue while debugging String.hashCode() line: not available i have refereed this ,
Im facing the following problem: I want to integrate the mercurial hash into my
Am facing a problem, while creating components through TOM API using .NET/COM Interop. Actual
For example, fading from picture a to b with a cross-fade for the entire
Facing problem for generating SQL Server Query In the Following query dynamic conditions are
Cross-site request forgery is common on web now a days. I am facing this
I'm trying to write a site specific browser for a few sites and am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.