I wanted to change the behavior of the “Edit Item” button from the Sharepoint 2010 ribbon of the Display Form (DispForm.aspx). It wasn’t really easy, so I finally found a solution that I’m going to share here.
You’ll need to use JavaScript for that. In the below example, the click on the “Edit Item” will open the EditForm in a new window:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | function ribbonIsLoaded() { // find the button we want to change var a = document.getElementById( 'Ribbon.ListForm.Display.Manage.EditItem-Large' ); // remove the default action for this button Sys.UI.DomEvent.clearHandlers(a) // define your own action a.setAttribute( "onclick" , "" ); a.setAttribute( "target" , "_blank" ); a.setAttribute( "href" , window.location.href.replace(/DispForm.aspx/, "EditForm.aspx" ).replace(/&IsDlg=1/, "" )) } // Note: 'SOD' is an abbreviation for "Script on Demand" SP.SOD.executeOrDelayUntilScriptLoaded( function () { var pm = SP.Ribbon.PageManager.get_instance(); pm.add_ribbonInited( function () { ribbonIsLoaded(); }); var ribbon = null ; try { ribbon = pm.get_ribbon(); } catch (e) { } if (!ribbon) { if ( typeof (_ribbonStartInit) == 'function' ) _ribbonStartInit(_ribbon.initialTabId, false , null ); } else { ribbonIsLoaded(); } }, 'sp.ribbon.js' ); |