SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 3 down vote accepted

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);
share|improve this answer
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
umh, you might look into $clearHandlers etc, post about it:… , don't know if it works – Anders Aune May 16 '13 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>
share|improve this answer
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 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.