2014-01-14 69 views
1

我有一個按鈕鏈接(hyperlink)這個超級鏈接:無法與它對應的HTML代碼,點擊使用Greasemonkey的

<span title="Enroll in Classes" class="SSSBUTTON_CONFIRMLINK"> 
<a class="SSSBUTTON_CONFIRMLINK" href="javascript:submitAction_win0(document.win0,'DERIVED_REGFRM1_LINK_ADD_ENRL$118$');" tabindex="202" ptlinktgt="pt_peoplecode" id="DERIVED_REGFRM1_LINK_ADD_ENRL$118$" name="DERIVED_REGFRM1_LINK_ADD_ENRL$118$">Proceed to Step 2 of 3</a> 
</span> 

我想點擊該按鈕,頁面加載10秒後,我使用下面的代碼:

​​

上述腳本不起作用,不點擊按鈕。有人可以指出這裏有什麼問題嗎?

編輯: 我得到以下錯誤在控制檯

ERROR: Execution of script 'Add to cart' failed! Object [object global] has no method 'clickOnProceedButton' 
TypeError: Object [object global] has no method 'clickOnProceedButton' 
    at Object.eval (unknown source)), 25:14) 
    at Object.eval (unknown source)), 27:4) 
    at ag (unknown source), 190:4) 
    at K (unknown source), 190:46) 
    at o (unknown source), 456:2) 
    at U (unknown source), 460:85) 
    at R (unknown source), 229:40) 

提前感謝!

+0

我想你需要逃避'$'所以儘量'變種targSubmit = $( 「#DERIVED_REGFRM1_LINK_ADD_ENRL \\ $ 118 \\ $」);' – Satpal

+0

@Satpal - 對不起,不能正常工作。 – Rajath

回答

1

谷歌瀏覽器完美的工作,但在不工作IE8

JSFiddle

HTML:

<a href="https://google.com" id="DERIVED_REGFRM1_LINK_ADD_ENRL$118$" >Proceed to Step 2 of 3</a> 

JS:

function clickOnProceedButton() { 
var targSubmit = document.getElementById("DERIVED_REGFRM1_LINK_ADD_ENRL$118$"); 
var clickEvent = document.createEvent('MouseEvents'); 
clickEvent.initEvent ('click', true, true); 
targSubmit.dispatchEvent(clickEvent); 

}

可能對您有幫助。

+0

這不起作用!甚至無法彈出警報窗口。 – Rajath

+0

在哪個瀏覽器上使用..? –

+0

Firefox。但是用Tampermonkey擴展也可以用Chrome來試用它。 – Rajath

1
setInterval(clickOnProceedButton, 10 * 1000); 
function clickOnProceedButton() { 
    var link = document.getElementById("DERIVED_REGFRM1_LINK_ADD_ENRL$118$"); 
    if(link) { 
     link.click(); 
    } 
} 

Demo

+0

看來document.getElementById()沒有檢索任何東西。所以點擊操作不會發生。你的演示效果很好。 – Rajath