2014-02-19 3 views
1

콘텐츠 스크립트를 통해 인위적으로 클릭을 유도하려고합니다. 동일한 코드가 작동하고 콘솔에서 시도 할 때 클릭을 트리거하지만 contentscript에서 시도한 경우에는 그렇지 않습니다.콘솔과 콘텐츠 스크립트에서 동일한 코드를 실행하는 동안의 출력 차이

내가 클릭을 적용하고있는 선택한 요소를 에코하려고하면,이 있어요 : -

통해 콘솔을

[<a class=​"blue apply-coupon">​APPLY COUPON​</a>​] 

SO, 링크가 제대로 여기에 선택

Contentscript를 통해이 객체와 같은 링크를 얻었습니다.

[a.blue.apply-coupon, prevObject: e.fn.e.init[1], context: document, selector: ".coupon-section a", constructor: function, init: function…] 

.click()을 클릭하고 클릭을 균등하게하고 트리거링하여 두 번 클릭합니다. -

1. $('.coupon-section').find('a').click(); 

2. var e = jQuery.Event("click"); 
jQuery('.coupon-section a').trigger(e); 

아무도 작동하지 않습니다. 누구든지 내가 뭘 잘못하고 있는지 제시 할 수 있으며 링크가 객체로 사용 가능할 때 어떤 방법 으로든 트리거 할 수 있습니다 (내용 스크립트의 경우 사용할 수 있음).

업데이트 : 링크 개체를 확장 할 때이 문제가 발생합니다. 개체를 클릭 할 때까지만 추가하고 있습니다.

0: a.blue.apply-coupon 
context: document 
length: 1 
prevObject: e.fn.e.init[1] 
0: div.coupon-section 
context: document 
length: 1 
prevObject: e.fn.e.init[1] 
selector: ".coupon-section" 
__proto__: Object[0] 
_toggle: function (a){var b=arguments,c=a.guid||f.guid++,d=0,e=function(c){var e=(f._data(this,"lastToggle"+a.guid)||0)%d;f._data(this,"lastToggle"+a.guid,e+1),c.preventDefault();return b[e].apply(this,arguments)||!1};e.guid=c;while(d<b.length)b[d++].guid=c;return this.click(e)} 
add: function (a,b){var c=typeof a=="string"?f(a,b):f.makeArray(a&&a.nodeType?[a]:a),d=f.merge(this.get(),c);return this.pushStack(S(c[0])||S(d[0])?d:f.unique(d))} 
addClass: function (a){var b,c,d,e,g,h,i;if(f.isFunction(a))return this.each(function(b){f(this).addClass(a.call(this,b,this.className))});if(a&&typeof a=="string"){b=a.split(p);for(c=0,d=this.length;c<d;c++){e=this[c];if(e.nodeType===1)if(!e.className&&b.length===1)e.className=a;else{g=" "+e.className+" ";for(h=0,i=b.length;h<i;h++)~g.indexOf(" "+b[h]+" ")||(g+=b[h]+" ");e.className=f.trim(g)}}}return this} 
after: function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,f.clean(arguments));return a}} 
ajaxComplete: function (a){return this.on(b,a)} 
ajaxError: function (a){return this.on(b,a)} 
ajaxSend: function (a){return this.on(b,a)} 
ajaxStart: function (a){return this.on(b,a)} 
ajaxStop: function (a){return this.on(b,a)} 
ajaxSuccess: function (a){return this.on(b,a)} 
andSelf: function(){return this.add(this.prevObject)} 
animate: function (a,b,c,d){function g(){e.queue===!1&&f._mark(this);var b=f.extend({},e),c=this.nodeType===1,d=c&&f(this).is(":hidden"),g,h,i,j,k,l,m,n,o;b.animatedProperties={};for(i in a){g=f.camelCase(i),i!==g&&(a[g]=a[i],delete a[i]),h=a[g],f.isArray(h)?(b.animatedProperties[g]=h[1],h=a[g]=h[0]):b.animatedProperties[g]=b.specialEasing&&b.specialEasing[g]||b.easing||"swing";if(h==="hide"&&d||h==="show"&&!d)return b.complete.call(this);c&&(g==="height"||g==="width")&&(b.overflow=[this.style.overflow,this.style.overflowX,this.style.overflowY],f.css(this,"display")==="inline"&&f.css(this,"float")==="none"&&(!f.support.inlineBlockNeedsLayout||cv(this.nodeName)==="inline"?this.style.display="inline-block":this.style.zoom=1))}b.overflow!=null&&(this.style.overflow="hidden");for(i in a)j=new f.fx(this,b,i),h=a[i],cn.test(h)?(o=f._data(this,"toggle"+i)||(h==="toggle"?d?"show":"hide":0),o?(f._data(this,"toggle"+i,o==="show"?"hide":"show"),j[o]()):j[h]()):(k=co.exec(h),l=j.cur(),k?(m=parseFloat(k[2]),n=k[3]||(f.cssNumber[i]?"":"px"),n!=="px"&&(f.style(this,i,(m||1)+n),l=(m||1)/j.cur()*l,f.style(this,i,l+n)),k[1]&&(m=(k[1]==="-="?-1:1)*m+l),j.custom(l,m,n)):j.custom(l,h,""));return!0}var e=f.speed(b,c,d);if(f.isEmptyObject(a))return this.each(e.complete,[!1]);a=f.extend({},a);return e.queue===!1?this.each(g):this.queue(e.queue,g)} 
append: function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})} 
appendTo: function (c){var d=[],e=f(c),g=this.length===1&&this[0].parentNode;if(g&&g.nodeType===11&&g.childNodes.length===1&&e.length===1){e[b](this[0]);return this}for(var h=0,i=e.length;h<i;h++){var j=(h>0?this.clone(!0):this).get();f(e[h])[b](j),d=d.concat(j)}return this.pushStack(d,a,e.selector)} 
attr: function (a,b){return f.access(this,a,b,!0,f.attr)} 
before: function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=f.clean(arguments);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}} 
bind: function (a,b,c){return this.on(a,null,b,c)} 
blur: function (a,c){c==null&&(c=a,a=null);return arguments.length>0?this.on(b,null,a,c):this.trigger(b)} 
change: function (a,c){c==null&&(c=a,a=null);return arguments.length>0?this.on(b,null,a,c):this.trigger(b)} 
children: function (c,d){var e=f.map(this,b,c);L.test(a)||(d=c),d&&typeof d=="string"&&(e=f.filter(d,e)),e=this.length>1&&!R[a]?f.unique(e):e,(this.length>1||N.test(d))&&M.test(a)&&(e=e.reverse());return this.pushStack(e,a,P.call(arguments).join(","))} 
clearQueue: function (a){return this.queue(a||"fx",[])} 
click: function (a,c){c==null&&(c=a,a=null);return arguments.length>0?this.on(b,null,a,c):this.trigger(b)} 

제 질문에 대해 명확하지 않은 경우 의견을 보내 주시기 바랍니다.

감사합니다.

답변

0

일시적으로 자바 스크립트를 사용하여이 문제를 해결 : -

document.getElementsByClassName('apply-coupon')[0].click(); 

여전히 그가 jQuery를 통해 클릭하기되지 않은 이유를 알고 싶어요!