Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I built a WebPart for SharePoint 2010, in this WebPart, when I click a button, it will popup a dialog which contains an image, I just call the sp.ui.modaldialog api direcyly.

ExecuteOrDelayUntilScriptLoaded(function(){SP.UI.ModalDialog.showModalDialog(options)}, “sp.ui.dialog.js”)  

As SharePoint 2013 is released, I want to move this WebPart to SharePoint 2013, but I met a problem after the migration. When an user log in, the popup works well, but if current user is anonymous, it doesn't work.
I tried to debug it, and I found the variable "g_ExecuteOrWaitJobs" contains all the events to be executed as soon as js is loaded. My function is also in the waiting jobs queue, but the property "notified" is false, which explains why popup is not triggered.
So I checked the scripts in the page, the developer tool shows that all the "sp.*.js" are not registered to the page.

So I got the reason, as "sp.ui.dialog.js" is not registered, my function will never be notified. but in SharePoint 2010, "sp..js" are registered for anonymous user(and also in "SharePoint 2010" view in SharePoint 2013), why is it changed? If we see the page source, it will register the "sp..js", why is it not registered at last?

<script type="text/javascript">RegisterSod("sp.ui.dialog.js", "\u002f_layouts\u002f15\u002fsp.ui.dialog.debug.js?rev=2hnmqeYvKPxuEddYqrW\u00252F0A\u00253D\u00253D");

How to call the SP.UI.ModalDialog.showModalDialog function for anonymous user? Thanks in advance.

share|improve this question
    
Did you find any answer for this? I am also looking for the same answer or any relevant documentation. –  Vardhaman Deshpande Dec 14 '12 at 15:12
    
@VardhamanDeshpande you can use the "SP.SOD.executeFunc(key, functionName, fn)" method. It will load the script if it's not loaded yet. –  Xiaodan Mao Dec 16 '12 at 5:48
    
@VardhamanDeshpande The way of registering sp.js(for example) is different from registering it directly. <script type="text/javascript">RegisterSod(file, url) will not load js immediately. It will be loaded only when it's required.(for more details, please check this article:ilovesharepoint.com/2010/08/…) So I just guess that when current user is anonymous, some common functions will not be required and executed, and these functions are related to "sp.*.js", so the js files will not be loaded. –  Xiaodan Mao Dec 16 '12 at 5:57
    
Well my issue is a little different, when working with publishing sites, if a page is not checked in, then the sp.*.js files are loaded. But as soon as the page is checked in and published, the files stop loading. –  Vardhaman Deshpande Dec 16 '12 at 15:06
    
@VardhamanDeshpande I also met this problem, and I found a question that describes this issue:social.msdn.microsoft.com/Forums/en-US/sharepointdevpreview/…, but the solution in the question is quite unclear. If you pay attention to the ribbon(Browse,Page) in your page, you will find that after the page is published, the ribbon is gone. Because the ribbon relys on "sp.*.js", so if the ribbon appears in the page, sp.js will be loaded. All in all, for some reasons, sp.js is not required(ribbon is just one way that will require sp.js) in your page. –  Xiaodan Mao Dec 17 '12 at 6:38
show 1 more comment

1 Answer

@Xiadon Mao, you could try the following on your master page.

<SharePoint:ScriptLink ID="ScriptLink1" Name="SP.js" runat="server" OnDemand="false" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink ID="ScriptLink2" Name="SP.UI.Dialog.js" runat="server" OnDemand="false" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink ID="ScriptLink3" Name="SP.Ribbon.js" runat="server" OnDemand="false" LoadAfterUI="true" Localizable="false"/>

That's how I pre-load everything to make sure all the scripts work -- especially when I use other browsers, where the javascript loading occurs differently. (e.g. Google Chrome). I have some more on improving the loading, particular with Google Chrome, in my blog.

share|improve this answer
    
Thanks for your answer, your information is useful. But in our situation, we are not allowed to modify our customers' master page. I've found that SP.SOD.executeFunc(key, functionName, fn) can solve this problem. –  Xiaodan Mao Feb 23 '13 at 11:10
    
Great one. You have saved my day buddy :) –  suryakiran Nov 20 '13 at 14:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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