1

I am adding a custom menu item in SharePoint Online ECB. I am using following code.

function AddCustomUserActionToECB() {
var testt = "javascript:callChatApp();";
var CstomAName = $("#text1").val();
var clientContext = new SP.ClientContext();
var oWeb = clientContext.get_web();
var oList = oWeb.get_lists().getByTitle('Documents');
var userCustomActionColl = oList.get_userCustomActions();
var oUserCustomAction = userCustomActionColl.add();
oUserCustomAction.set_location('EditControlBlock');
oUserCustomAction.set_sequence(100);
oUserCustomAction.set_title(CstomAName);
oUserCustomAction.set_url(testt);
oUserCustomAction.update(); clientContext.load(userCustomActionColl); clientContext.executeQueryAsync(QuerySuccess, QueryFailure);
        }
function QuerySuccess() {
   console.log("Custom Action added to ECB menu.");
}
function QueryFailure() {
   console.log('Request failed - ' + args.get_message());
}

The code is working fine. Now I have a javascript function which should be called on ECB item click. The function code is:

function callChatApp() {

// Some javascript code.

$('#AnotherButton').trigger('click',function(e){
// e.stopPropagation(); // Sample tried code
//e.preventDefault(); // Sample tried code
});
//return false; // Sample tried code
}

Here the button triggers, but the page get refreshed so my pop up get closed. I want to prevent the page refresh here.

I browsed SO and found so may solution but none of them worked in SharePoint.

How I can prevent page reloading on ECB menu item clicked?

2 Answers 2

3

event.StopPropagation();

or

event.preventDefault();

are the JavaScript ways of canceling an event

Are you sure there are no other (SharePoint) events involved?

Use F12 check every relevant child element if there are event listners (or write some script to check)

0
0

I faced the same issue. The below code helps me

<input type="button" value="Click me" onClick="AddCustomUserActionToECB();return false;"/>
1
  • Thanks, this should work definetly, But I want to prevent refreshing after callChatApp() function executes. And I have already tried return false, you can find in my answer code.. Commented Jun 5, 2017 at 9:34

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.