Jquery - Simulating click button doesn't trigg

2019-07-03 00:35发布

问题:

Ok,

So I have been using firebug and also some extensions I wrote to create shortcuts on website I use often. There's on thing that I don't understand why it doesn't work or why it's not possible:

Example code:

<input type="button" onclick="addNewRow()" id="addRow"/>
//This will add a new row to the current table.
//The function is defined by the website (not my function)

When using firebug:

jQuery("#addRow").click();
//This will simulate the button click, and will automatically add the new row.

When using google chrome extension:

jQuery("#addRow").click();
//It doesn't add the new row.

Why can't the extension execute the function once the button click occurs, and why firebug has no issues in running it?

Is this normal? Is this a security feature? or am I doing something wrong?

I know that I can't access existing functions in a website for security reasons, but why won't the button simulation trigger it for me?

回答1:

Try:

jQuery("#addRow").trigger("click");


回答2:

What version of Chrome are you using ? There is a new Chrome Extensions security feature that blocks inline javascript. You can read more here : http://browserfame.com/512/chrome-extension-content-security-policy



回答3:

On chrome, I would rather use WebKit's developer console rather than firebug extention.