Jquery - Simulating click button doesn't trigg

2019-07-03 00:43发布

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?

3条回答
放荡不羁爱自由
2楼-- · 2019-07-03 01:17

Try:

jQuery("#addRow").trigger("click");
查看更多
来,给爷笑一个
3楼-- · 2019-07-03 01:21

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

查看更多
欢心
4楼-- · 2019-07-03 01:38

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

查看更多
登录 后发表回答