Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
362 views
in Technique[技术] by (71.8m points)

javascript - Google Chrome: JQuery content script on Facebook

I am using Google Chrome and I'm writing a browser extension. I'm trying to inject JQuery 2.0.3 into facebook as a context script. Just to see if I could, I'm trying to grab the text area on the message page. I'm typing this line directly into the Javascript console:

$('textarea[name="message_body"]');

Instead of getting a JQuery object I'm getting this error:

Error: <![EX[["Tried to get element with id of "%s" but it is not present on the page.","undefined"]]]>

Does facebook have anti-jquery measures or is there something else happening that I'm doing wrong? As usual, thanks all in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are accessing a $() function defined in the Facebook page, which has nothing to do with jQuery. To access the execution context of you content scripts from the javascript console, you need to select it from the drop down box located at the bottom of the window:

Bottom bar of Developer Tools

Instead of <page context>, you have to select chrome-extension://<your extension id>.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...