{"id":1396,"date":"2014-07-28T11:44:55","date_gmt":"2014-07-28T09:44:55","guid":{"rendered":"http:\/\/blog.kodono.info\/wordpress\/?p=1396"},"modified":"2015-09-18T09:46:01","modified_gmt":"2015-09-18T07:46:01","slug":"how-to-edit-the-default-action-for-an-icon-in-a-sharepoint-ribbon","status":"publish","type":"post","link":"https:\/\/blog.kodono.info\/wordpress\/2014\/07\/28\/how-to-edit-the-default-action-for-an-icon-in-a-sharepoint-ribbon\/","title":{"rendered":"How to edit the default action for an icon in a Sharepoint Ribbon"},"content":{"rendered":"<p>I wanted to change the behavior of the &#8220;Edit Item&#8221; button from the Sharepoint 2010 ribbon of the Display Form (DispForm.aspx). It wasn&#8217;t really easy, so I finally found a solution that I&#8217;m going to share here.<\/p>\n<p>You&#8217;ll need to use JavaScript for that. In the below example, the click on the &#8220;Edit Item&#8221; will open the EditForm in a new window:<\/p>\n<pre class=\"brush: javascript\">\r\nfunction ribbonIsLoaded() {\r\n  \/\/ find the button we want to change\r\n  var a = document.getElementById('Ribbon.ListForm.Display.Manage.EditItem-Large');\r\n  \/\/ remove the default action for this button\r\n  Sys.UI.DomEvent.clearHandlers(a)\r\n  \/\/ define your own action\r\n  a.setAttribute(\"onclick\",\"\");\r\n  a.setAttribute(\"target\", \"_blank\");\r\n  a.setAttribute(\"href\", window.location.href.replace(\/DispForm.aspx\/,\"EditForm.aspx\").replace(\/&#038;IsDlg=1\/,\"\"))\r\n}\r\n\/\/ Note: 'SOD' is an abbreviation for \"Script on Demand\"\r\n\r\nSP.SOD.executeOrDelayUntilScriptLoaded(function () {\r\n  var pm = SP.Ribbon.PageManager.get_instance();\r\n  pm.add_ribbonInited(function () {\r\n    ribbonIsLoaded();\r\n  });\r\n  var ribbon = null;\r\n  try\r\n  {\r\n    ribbon = pm.get_ribbon();\r\n  } \r\n  catch (e) {\r\n  }\r\n  if (!ribbon) {\r\n    if (typeof (_ribbonStartInit) == 'function')\r\n    _ribbonStartInit(_ribbon.initialTabId, false, null);\r\n  } \r\n  else {\r\n    ribbonIsLoaded();\r\n  }\r\n}, 'sp.ribbon.js');\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to change the behavior of the &#8220;Edit Item&#8221; button from the Sharepoint 2010 ribbon of the Display Form (DispForm.aspx). It wasn&#8217;t really easy, so I finally found a solution that I&#8217;m going to share here. You&#8217;ll need to use JavaScript for that. In the below example, the click on the &#8220;Edit Item&#8221; will [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","hide_page_title":"","footnotes":""},"categories":[13,33],"tags":[24,152,158,117],"class_list":["post-1396","post","type-post","status-publish","format-standard","hentry","category-niveau-intermediaire","category-programmation","tag-javascript","tag-niveau-intermediaire","tag-programmation","tag-sharepoint"],"_links":{"self":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1396","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/comments?post=1396"}],"version-history":[{"count":3,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1396\/revisions"}],"predecessor-version":[{"id":1541,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1396\/revisions\/1541"}],"wp:attachment":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/media?parent=1396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/categories?post=1396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/tags?post=1396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}