Emulate clicking a link with Javascript that works with IE

后端 未结 5 921
别那么骄傲
别那么骄傲 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条回答
  •  执念已碎
    2020-12-02 21:47

    This didn't work for me at first and then I saw the code is missing a parameter for the IE portion. Here's an update that should work:

    function fireEvent(obj, evt) {
        var fireOnThis = obj;
    
        if (document.createEvent) {
            // alert("FF");
            var evtObj = document.createEvent('MouseEvents');
            evtObj.initEvent(evt, true, false);
            fireOnThis.dispatchEvent(evtObj);
        } 
    
        else if (document.createEventObject) {
            // alert("IE");
            var evtObj = document.createEventObject();
            fireOnThis.fireEvent('on'+evt, evtObj);
        }
    }
    

提交回复
热议问题