In SharePoint, when I need to execute an action when the user doesn’t have privileges to do so, I use:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
// DO SOMETHING WITH PRIVILEGES
});
But now I need to execute JavaScript with elevated privileges:
var context = new SP.ClientContext.get_current();
context.executeQueryAsync(); // NEED PRIVILEGES TO WORK
Is this possible?
No, that isn’t possible.
The user would be able to manipulate the JavaScript which would open a huge security gap. You just can do this on the server-side. If you need something like this it must all take place at the server.