0

I need to refer jquery in spBodyOnLoadFunctionNames.push function. I am doing it like below

_spBodyOnLoadFunctionNames.push("Testfunction"); function Testfunction() { }

but because of two script tag, there is a problem. my master page does not include jquery. and one button uses jquery of which code is out of my control If I add simple jquery reference, it works after page refresh and not instantly. so I am trying with this way. any other idea will be better. Thanks

  • I use jquery all the time and i've never used _spBody... in I.E. press f12 and in console write:$.fn.jquery. If you get the jQuery Version, then search the problem elsewhere – XristosK Sep 5 '14 at 20:32
  • I'm not sure I understand the behavior you're describing. You want to use jQuery inside of this function Testfunction right? I understand you're saying there is another control on the page that loads jQuery independently and that you cannot modify it -- but what do you mean by "it works after page refresh and not instantly"? What works? Does the function fire or you can get a jQuery reference on the page? It would help if you posted at least a summary of what your script does, more helpful would be the entire source -- and it would really help to know how you're adding the script to the page – John-M Sep 6 '14 at 22:03
  • Many thanks for your reply. I have newsgator webpart in which there is "Like" button which uses jquery to increment counter when user likes that post. but at this moment, when user clicks on like button, like counter doesnt increase instantly. so I added jquery reference through CEWP. And now when user clicks on like button, it increments counter after page refresh ...and not instantly. So i think its not getting jquery reference to increment counter instantly but it gets it after page refresh and then it incremnets it. i hope its clear now – Rajeev K Sep 9 '14 at 9:37
0

If it is already working but you have to reload the page, just use

location.reload(true);

at the end of your function and that will solve your problem of having to refresh the page for it to show the change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.