Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running JQuery or Javascript on Facebook

I am trying to execute a simple bit of jQuery or JavaScript once logged in to my Facebook account. The end goal at this moment is to click on my custom feed once the element is visible, rather than having it default to the entire Facebook friend feed.

On trying to code this using my Developer's Console in Chrome no JavaScript/jQuery seems to work at all. Even just a simple $('div'); returns null. Is it possible to run code on Facebook's page? What are they doing differently?

I guess the end goal would be to click a div if the .val('give a waffle'); but just understanding why it has not worked until now would also be interesting.

Any hints, tips or suggestions are more than welcome.

like image 664
edev.io Avatar asked Dec 17 '22 04:12

edev.io


1 Answers

Facebook doesn't use jQuery, if you want to play with their page using jQuery commands you'll need to load it. Just copy the contents of http://code.jquery.com/jquery-1.7.1.min.js and paste it into your console first. Then proceed as usual.

Additionally you could let Google host your jQuery :

<script type="text/javascript"
 src="//code.jquery.com/jquery-2.2.0.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    // This is more like it!
  });
</script>

Many sites do this so the chances of your user already having the library cached is relatively high.

like image 56
Sinetheta Avatar answered Dec 29 '22 14:12

Sinetheta