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 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?

share|improve this question

2 Answers 2

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
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

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
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

 
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.