0

I am using Chrome (I know not fully supported) and I wrote a small little script to display the weather using jQuery and Yahoo weather.

The problem is once I placed it on the page, some parts of the ribbon (edit, page, browse, publish) no longer work in Chrome. Now while I know Chrome is not supported, it worked before.

This is my 1st little test in using jQuery within SharePoint, I launch the developer tools in Chrome (F12) to view the console and there are no errors.

Is there any other way I can try to debug what is happening?

0

3 Answers 3

1

This is most likely because the <body> attribute onload is not reached, or even overwritten by jQuerys document ready.

You can fix this by calling _spBodyOnLoadWrapper(), for example like this:

$(function() { 
  (window.navigator.userAgent + '').match(/Chrome/) && 
    !_spBodyOnLoadCalled && 
    window._spBodyOnLoadWrapper && 
    _spBodyOnLoadWrapper(); 
});
3
  • Do I put this in the same script in my weather widget?
    – mdumka
    Commented Nov 27, 2012 at 15:50
  • Anywhere you like really, for example with script link. But to test this solution you can open up your console (F12) and run _spBodyOnLoadWrapper(), if this works you should immediately see improvements.
    – eirikb
    Commented Nov 27, 2012 at 19:08
  • My god man ... you are a lifesaver! Thanks soooo Much!
    – mdumka
    Commented Nov 29, 2012 at 18:21
0

I've never had any huge issues with the combination of Chrome, jQuery, and SharePoint that I can remember. Where are you calling your jQuery script? Header? Footer? And what are you calling your scripts on? I typically call on

$(document).ready(function(){
  // script here
})

and have never had problems in the past. Can you paste any kind of code sample? I can't confirm @eirikb's solution, but it sounds like it might help.

0

I would fix your issue by simulating JQuery's way of doing things and use an iifee to wrap your code up giving yourself localised variables.

The JQuery iife (Immediately invoked function expression) looks like this:

(function(window,document,undefined) {
    ... code here
})(this,document);

this refers to the window object in this case.

JQuery should never overwrite the document because of this, it actually has it's own copy to play with, so if it is then some thing's are broken with your JQuery.

So make yourself an instanced version of the page, and you should be fine for calling your functions, it's also good practice while working with any code to scope your variables, and iifes are used to scope variables in Javascript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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