Emulate clicking a link with Javascript that works with IE

后端 未结 5 917
别那么骄傲
别那么骄傲 2020-12-02 20:40

I want to have java script clicking a link on the page..I found something on the net that suggests adding a function like this:

function fireEvent(obj,evt){
         


        
5条回答
  •  Happy的楠姐
    2020-12-02 21:27

    I think you still need to call document.createEventObject -- you only checked that it's there. Untested code follows, but based on the docs it should work.

    function fireEvent(obj,evt){
    
        var fireOnThis = obj;
        if( document.createEvent ) {
          var evObj = document.createEvent('MouseEvents');
          evObj.initEvent( evt, true, false );
          fireOnThis.dispatchEvent( evObj );
    
        } else if( document.createEventObject ) {
          var evObj = document.createEventObject();
          fireOnThis.fireEvent( 'on' + evt, evObj );
        }
    }
    

提交回复
热议问题