Skip to main content

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.


Comments

  1. 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="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.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.

    ReplyDelete
  2. if("Developer's Console" == "https://developers.facebook.com/tools/console/") {
    answer = "no";
    } else {
    throw new Exception("unknown error");
    }

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?