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']");
function fAddScriptToQueue() {
    ExecuteOrDelayUntilScriptLoaded(fGetCloseBtn, "SP.js");

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?


2 Answers 2


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, 2013 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 May 16, 2013 at 11:35

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, 2013 at 6:43

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.