3

I have override new item form for list, opening myPage.aspx where this javascript is in the "PlaceHolderAdditionalPageHead":

function fGetCloseBtn() {
    var closeButton = jQuery("a[id^='DlgClose']");
    console.log(closeButton.lenght);
    }       
function fAddScriptToQueue() {
    ExecuteOrDelayUntilScriptLoaded(fGetCloseBtn, "SP.js");
};  
_spBodyOnLoadFunctionNames.push("fAddScriptToQueue");

When page loaded, Log shows 0. Inspecting element in IE Dev Tools show that it exist. So, did I picked the wrong time to select element? Or has modal dialog other dependencies then SP.js?

4

If you are talking about the button on the top (X). The controls up there are part of the parent window iirc.

So try changing it to:

 var closeButton = jQuery("a[id^='DlgClose']",parent.document);
  • To prevent dialog from closing, I tried event.stopImmediatePropagation(); for the 'click' event of that (X) button. Doesn't work. Any ideas? – dbardakov May 16 '13 at 8:26
  • 1
    umh, you might look into $clearHandlers etc, post about it: social.technet.microsoft.com/forums/en-US/… , don't know if it works – Anders Aune May 16 '13 at 11:35
1

To work with the SharePoint JS library you must have the SP.js at least:

<script type="text/javascript" src="/_layouts/SP.js"></script>
<script type="text/javascript" src="/_layouts/SP.UI.Dialog.js"></script>
<script type="text/javascript" src="/_layouts/SP.Core.js"></script>
  • 1
    As @Anders indicated, this code executes from inside dialog iframe, so all dependencies allready here. It is even unnecessary to call ExecuteOrDelayUntilScriptLoaded(fGetCloseBtn, "SP.js"); – dbardakov May 17 '13 at 6:43

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.