javascript - Why does a script work in Firebug's command line on one site but not on another? -


i using firefox , firebug's command line execute javascript on 2 different sites:

  1. https://graph.facebook.com/v2.3/172727819415642/albums?fields=id,name,cover_photo,photos%7bname,source%7d&limit=1&access_token=xxxxx
  2. http://www.iskcondesiretree.com/photo/album/list

here's code:

(function() {    function r() {        = $("body").text()        console.log(a);    };    var e = "1.6.4";    var t = false;    if (!t) {        t = true;        var n = document.createelement("script");        n.src = "https://ajax.googleapis.com/ajax/libs/jquery/" + e + "/jquery.min.js";        n.onload = function() {            r();        };         document.getelementsbytagname("head")[0].appendchild(n);    }; })(); 

when run code in firebug's command line on site 1, returns following error:

typeerror: $(...).text() not function

when run code site 2 works fine. shows lot of text site.

interesting thing is, if change $ jquery works on site 1, too.

can tell what's happening? why firebug behaves differently 2 sites?

the dollar sign used internally firebug's command line @ time page loaded on site 1. if page sets $ variable itself, firebug try use variable instead of own $ command, case on site 2.

to avoid such conflicts should use jquery instead of $ within command line when want access jquery functionality.

your code this:

(function() {   function r() {     = jquery("pre").text();     console.log(a);     b = a.replace(/this nice car/g, "happy birthday");     console.log(b);   };   var e = "1.6.4";   var t = false;   if (!t) {     t = true;     var n = document.createelement("script");     n.src = "https://ajax.googleapis.com/ajax/libs/jquery/" + e + "/jquery.min.js";     n.onload = function() {       r();     };      document.getelementsbytagname("head")[0].appendchild(n);   }; })(); 

note: code above avoids double loading of jquery checking t variable before request made. , incorrect use of onreadystatechange , readystate removed, because available xmlhttprequests, not appended <script> tags.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -