简体   繁体   中英

How to trigger a “click” event on an invisible button in IE9?

Because of some very weird authorization problems, my CSS (or something) gets messed up and I can't see my button (<a..> anchor actually). I am using IE9 and don't have the option of using something else. As far as I see JQuery 1.10.2 is loaded.

I'm not very interested in seeing my button, just in clicking on it, because I don't want to fix the CSS, I just want to access the backend (I'm not the frontend guy in this story).

My button looks like this:

<a onclick="js.search()" href="javascript:void(0)" id="asdf12345">Search<img class="r" src="im/arrow-gray.gif"/></a>

What I've tried:

  • First, I entered the id manually, within the IE9 Developer tools > HTML tab. (the anchor had no id- that's why)
  • Tried to invoke the "js.search()" function manually, but js is not defined.
  • I tried using the jQuery selector for the precise ID $('#asdf12345').trigger("click"); but it also doesn't do anything.

I'm not very experienced in the frontend, for instance I don't know why the "js" object isn't within scope in the console (cuz I can call the alert('asdf'); function for instance, so something does work).

So if anyone is aware of any way in which i can call my backend, simulating a click, that would help a lot!

[EDIT] After failing to trigger the onClick programatically, taking Alex Shilman's suggestion, I messed around with the CSS - making my fonts smaller made it so that my images fit on the screen, so I could click on them.

Take the inline onclick out and create an event handler with jquery like this:

html:

<a id="asdf12345"> Search <img class="r" src="im/arrow-gray.gif"/></a>

JS:

 $(function(){
  $('body').on('click', '#asdf12345', function(e){
    e.preventDefault();
    alert('clicked anchor');
  });
});

then you can do:

$('#asdf12345').trigger("click");

If you're not seeing you image on the screen, try fiddling around with the css.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM