/    Sign up×
Community /Pin to ProfileBookmark

click() for Firefox?

Hi. Click works for IE on some anchors i have, but not Firefox, anyone know of anything? Thanks in advance.

to post a comment
JavaScript

20 Comments(s)

Copy linkTweet thisAlerts:
@JPnycApr 11.2006 — Click? There is no click event handler. onclick, but not click. However a simple anchor tag shouldn't require an onclick event handler added to it. What else is going on inside the tag?
Copy linkTweet thisAlerts:
@decibelauthorApr 11.2006 — document.element.click()! JPnyc, you need to study harder man! Its not an event handler, its a method
Copy linkTweet thisAlerts:
@David_HarrisonApr 11.2006 — He doesn't mean onclick="", he means someAnchor.click() as a means to active it, as if the user clicked on it.

That's an IE only piece of code, so you can't use it in anything but IE. If you want to change the page with JavaScript, you could simply look at the href of the link instead, then redirect the user using location.href.
Copy linkTweet thisAlerts:
@JPnycApr 11.2006 — LOL, where did you get that? Oh, i thought he was trying to add an event handler in the anchor tag.

If it doesn't work, it must be the way you're referencing the element in question.
Copy linkTweet thisAlerts:
@decibelauthorApr 11.2006 — nah i dont want to change the page, i need to activate AJAX functionality on page load, depending on the referrer page. Somebody told me there was some way to get firefox to mimic this. Thanks for the help.
Copy linkTweet thisAlerts:
@JPnycApr 11.2006 — Then why not test for the referrer?
Copy linkTweet thisAlerts:
@decibelauthorApr 11.2006 — But i still need to active the click() homie... its AJAX
Copy linkTweet thisAlerts:
@David_HarrisonApr 11.2006 — If you need to run the functions in the onclick event handler of a link, then why not simply call them rather than using click().
Copy linkTweet thisAlerts:
@decibelauthorApr 11.2006 — Ajax!
Copy linkTweet thisAlerts:
@David_HarrisonApr 11.2006 — Congratulations, you've proved you can overuse buzzwords. Now how about showing some code and actually explaining why you can't just use a simple function call.
Copy linkTweet thisAlerts:
@decibelauthorApr 11.2006 — i appreciate the help, but can we forget the why, and move on to the how... the site I am working on is being developed in jsp and ajax... the latter of which i am not an expert in.... we need a click() solution for firefox, can anyone give any suggestions that dont compromise our technology?
Copy linkTweet thisAlerts:
@David_HarrisonApr 11.2006 — Maybe if you were [i]more specific[/i]. Here is the way I see it.

You want to activate a link (which you CANNOT do in non-IE browsers). So either you want to change the page or you want to trigger an event handler.

Since you've already said you don't want to change the page, it must be that you want to fire the event handler.

Since event handlers are just used to run pieces of code, mainly function calls, why can't you just call whatever is in the event handler from the JavaScript itself? Surely using .click() is the long way round here.

i need to activate AJAX functionality on page load[/quote]So:<body onload="someFunction();">depending on the referrer page[/quote]And this is where the JSP comes in, you can detect the referer on the server-side, then alter the function call in the onload event handler as desired.

I don't see what the problem is here, so if I've missed something, please spell it out for me. That's why I'm asking for specifics, maybe the situation seems obvious from where you're sitting, but you've given very little away about it so I'm flying blind.
Copy linkTweet thisAlerts:
@decibelauthorApr 11.2006 — its not calling javascript event handlers, its calling java methods... again i just need to know if click() can be simulated in Firefox... its hard to explain how the java beans work
Copy linkTweet thisAlerts:
@David_HarrisonApr 11.2006 — Then I can't help you, because as far as I know, links can only do two things and I don't know anything about Java beans.

I would have thought that since you are using JSP the Java would be on the server-side, but if you're using Java on the client-side too, what is the need for AJAX?
Copy linkTweet thisAlerts:
@gphApr 11.2006 — Wrtten by Jason Karl Davis
<i>
</i>if(typeof HTMLElement!='undefined'&amp;&amp;!HTMLElement.prototype.click)
HTMLElement.prototype.click=function(){
var evt = this.ownerDocument.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
this.dispatchEvent(evt);
}
Copy linkTweet thisAlerts:
@gphApr 11.2006 — I can't remove the space in "fals e", 2nd last line
Copy linkTweet thisAlerts:
@David_HarrisonApr 11.2006 — That's to prevent long lines causing horizontal scrolling for the page, they didn't take the code out of vBulliten when they altered the CSS to allow the codebox to scroll. You could get rid of it by adding spaces in after the comma's in the arguement.

Pretty good script, I didn't know that browsers allowed that.
Copy linkTweet thisAlerts:
@JPnycApr 11.2006 — I remember that now. I've seen that before, but I never had need of it. There's always a way around it.
Copy linkTweet thisAlerts:
@gphApr 11.2006 — Thanks for the info David, it's fixed.

Yea, JKD is a wiz ?
Copy linkTweet thisAlerts:
@claire_mclisterMay 27.2008 — Hi,

I've been trying for the past two days to get the above code to work in FF 2.0 but it doesn't seem to do anything. Works in Safari 3.0.

Claire
×

Success!

Help @decibel spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...