Question

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?

Était-ce utile?

La solution

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)

Autres conseils

I faced the same issue. The below code helps me

<input type="button" value="Click me" onClick="AddCustomUserActionToECB();return false;"/>
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top