博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Microsoft Dynamics CRM 4.0 文章页面 添加自定义按钮

Posted on 2012-11-09 23:51  Hamilton Tan  阅读(474)  评论(0编辑  收藏  举报

 

<script type="text/javascript">

    function popshowM() {
        try {
            var currentid = ((((location.href).split('='))[1]).replace('{', '')).replace('}', '');
            debugger;
            if (currentid != null && currentid != undefined && currentid != "") {
                var url = '/ISV/Lovol_FileDownUpload/FileDownUpload.aspx?id=' + currentid;
                var para = 'dialogHeight:500px;dialogWidth:620px';
                window.showModalDialog(url, null, para);
            }
        }
    }catch (e) {
        alert(e.name + ":" + e.message);
    }

</script>

window.onload = function () {
var mnuBar1t = document.getElementById("mnuBar1");
var mnuBar1Ul = mnuBar1t.getElementsByTagName("ul");
mnuBar1Ul[0].innerHTML += "<LI class='ms-crm-Menu-Spacer' tabIndex='-1'>&nbsp;<IMG style='CLIP: rect(0px 4px 21px 0px); BACKGROUND-IMAGE: url(/_imgs/imagestrips/control_imgs_1.gif); WIDTH: 4px; BACKGROUND-POSITION-Y: -72px; HEIGHT: 21px' id=mnu_hSpacer alt='' src='/_imgs/imagestrips/transparent_spacer.gif'/>&nbsp;</LI>"
mnuBar1Ul[0].innerHTML += "<LI id='btnEmailArticle' class='ms-crm-Menu' title='附件' tabIndex='-1' onclick='window.execScript(action)' action='popshowM();'><SPAN class='ms-crm-Menu-Label'><A class='ms-crm-Menu-Label' tabIndex='-1' onClick='return false;' href='javascript:onclick();' target='_self'><img src='/_imgs/ico_18_debug.gif' alt='附件' tabindex='-1' class='ms-crm-Menu-ButtonFirst' src='/_imgs/ico_18_debug.gif'/><SPAN class='ms-crm-MenuItem-TextRTL' tabIndex='0'>附件</SPAN></A></SPAN></LI>";
}

 

html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>

<TABLE id="mnuBar1" class="ms-crm-MenuBar" cellSpacing=0 cellPadding=0>
<TBODY>
<TR>
<TD class="ms-crm-MenuBar-Items" noWrap align=left _iParentPopupHeight="51">
<UL class="ms-crm-MenuBar-Left">

<LI accessKey=F id=file class="ms-crm-Menu" tabIndex=-1 menu="mnufile">
<SPAN class="ms-crm-Menu-Label-Opened">
<A class="ms-crm-Menu-Label" tabIndex=-1>
<SPAN class="ms-crm-MenuItem-TextFirst" tabIndex=0>文件菜单(<U>F</U>)</SPAN>
<IMG style="CLIP: rect(0px 11px 16px 0px); BACKGROUND-IMAGE: url(/_imgs/imagestrips/control_imgs_1.gif); WIDTH: 11px; BACKGROUND-POSITION-Y: -32px; HEIGHT: 16px" id=mnuDown class="ms-crm-Menu-DownArrow" alt=更多 src="/_imgs/imagestrips/transparent_spacer.gif"/>
</A>
<A class="atLink" title=打开文件菜单(F)菜单的可访问表单 tabIndex=-1 onClick="return false;" href="javascript:onclick();" target=_self></A>
</SPAN>


<DIV style="DISPLAY: none">
<UL id=mnufile class="ms-crm-MenuList">
<LI id=_MIPrint class="ms-crm-MenuItem-Label" tabIndex=-1 key="P" action="Print();">
<SPAN class="ms-crm-MenuItem-Label">
<A class="ms-crm-MenuLink" tabIndex=-1 onClick="return false;" href="javascript:onclick();" target=_self>
<SPAN class="ms-crm-MenuItem-Icon"></SPAN>
<SPAN class="ms-crm-MenuItem-Text" tabIndex=0>打印(<U>P</U>)...</SPAN>
</A>
</SPAN>
</LI>

<LI class="ms-crm-MenuList-Spacer" tabIndex=-1><HR class="ms-crm-MenuList-Spacer"></LI>

<LI id=_MIwindowclose class="ms-crm-MenuItem-Label" tabIndex=-1 key="C" action="window.close();">
<SPAN class="ms-crm-MenuItem-Label">
<A class="ms-crm-MenuLink" tabIndex=-1 onClick="return false;" href="javascript:onclick();" target=_self>
<SPAN class="ms-crm-MenuItem-Icon"></SPAN>
<SPAN class="ms-crm-MenuItem-Text" tabIndex=0>关闭(<U>C</U>)</SPAN>
</A>
</SPAN>
</LI>
</UL>

</DIV>

</LI>

<LI accessKey=A id=action class="ms-crm-Menu" title=操作(A) tabIndex=-1 menu="mnuaction">
<SPAN class="ms-crm-Menu-Label">
<A class="ms-crm-Menu-Label" tabIndex=-1><IMG class="ms-crm-Menu-ButtonFirst" tabIndex=-1 alt=操作(A) src="/_imgs/mnu_actions.gif">
<SPAN class="ms-crm-MenuItem-Text" tabIndex=0>操作(<U>A</U>)</SPAN>
<IMG style="CLIP: rect(0px 11px 16px 0px); BACKGROUND-IMAGE: url(/_imgs/imagestrips/control_imgs_1.gif); WIDTH: 11px; BACKGROUND-POSITION-Y: -32px; HEIGHT: 16px" id=IMG1 class="ms-crm-Menu-DownArrow" alt=更多 src="/_imgs/imagestrips/transparent_spacer.gif"/>
</A>

<A class="atLink" title=打开操作(A)菜单的可访问表单 tabIndex=-1 onClick="return false;" href="javascript:onclick();" target=_self></A>

</SPAN>

<DIV style="DISPLAY: none">
<UL id=mnuaction class="ms-crm-MenuList">
<LI id=mnuShowComments class="ms-crm-MenuItem-Label" tabIndex=-1 action="ShowComments();">
<SPAN class="ms-crm-MenuItem-Label">
<A class="ms-crm-MenuLink" tabIndex=-1 onClick="return false;" href="javascript:onclick();" target=_self>
<SPAN class="ms-crm-MenuItem-Icon"></SPAN>
<SPAN class="ms-crm-MenuItem-Text" tabIndex=0>显示注释</SPAN>
</A>
</SPAN>
</LI>

<LI id=mnuEmailArticle class="ms-crm-MenuItem-Label" tabIndex=-1 action="EmailArticle();">
<SPAN class="ms-crm-MenuItem-Label">
<A class="ms-crm-MenuLink" tabIndex=-1 onClick="return false;" href="javascript:onclick();" target=_self>
<SPAN class="ms-crm-MenuItem-Icon"></SPAN>
<SPAN class="ms-crm-MenuItem-Text" tabIndex=0>电子邮件知识库文章</SPAN>
</A>
</SPAN>
</LI>
</UL>

</DIV>

</LI>

<LI id=_MBPrint class="ms-crm-Menu" title=打印 tabIndex=-1 onclick=window.execScript(action) action="Print();">
<SPAN class="ms-crm-Menu-Label">
<A class="ms-crm-Menu-Label" tabIndex=-1 onClick="return false;" href="javascript:onclick();" target=_self>
<IMG style="CLIP: rect(0px 16px 16px 0px); BACKGROUND-IMAGE: url(/_imgs/imagestrips/grid_ctrl_imgs.gif); WIDTH: 16px; BACKGROUND-POSITION-Y: -89px; HEIGHT: 16px" id=16_print class="ms-crm-Menu-ButtonFirst" tabIndex=-1 alt=打印 src="/_imgs/imagestrips/transparent_spacer.gif"/>
<SPAN class="ms-crm-MenuItem-TextRTL" tabIndex=0>打印...</SPAN>
</A>
</SPAN>
</LI>

<LI id=_MBwindowclose class="ms-crm-Menu" title=关闭(C) tabIndex=-1 onclick=window.execScript(action) action="window.close();">
<SPAN class="ms-crm-Menu-Label">
<A class="ms-crm-Menu-Label" tabIndex=-1 onClick="return false;" href="javascript:onclick();" target=_self>
<IMG class="ms-crm-Menu-ButtonFirst" tabIndex=-1 alt=关闭(C) src="/_imgs/ico/16_close.gif">
<SPAN class="ms-crm-MenuItem-TextRTL" tabIndex=0>关闭</SPAN>
</A>
</SPAN>
</LI>

<LI class="ms-crm-Menu-Spacer" tabIndex=-1>&nbsp;
<IMG style="CLIP: rect(0px 4px 21px 0px); BACKGROUND-IMAGE: url(/_imgs/imagestrips/control_imgs_1.gif); WIDTH: 4px; BACKGROUND-POSITION-Y: -72px; HEIGHT: 21px" id=IMG2 alt="" src="/_imgs/imagestrips/transparent_spacer.gif">&nbsp;
</LI>

<LI id=btnShowComments class="ms-crm-Menu" title=显示注释 tabIndex=-1 onclick=window.execScript(action) action="ShowComments();">
<SPAN class="ms-crm-Menu-Label">
<A class="ms-crm-Menu-Label" tabIndex=-1 onClick="return false;" href="javascript:onclick();" target=_self>
<IMG class="ms-crm-Menu-ButtonFirst" tabIndex=-1 alt=显示注释 src="/_imgs/ico_16_1082.gif">
<SPAN class="ms-crm-MenuItem-TextRTL" tabIndex=0>显示注释</SPAN>
</A>
</SPAN>
</LI>

<LI class="ms-crm-Menu-Spacer" tabIndex=-1>&nbsp;
<IMG style="CLIP: rect(0px 4px 21px 0px); BACKGROUND-IMAGE: url(/_imgs/imagestrips/control_imgs_1.gif); WIDTH: 4px; BACKGROUND-POSITION-Y: -72px; HEIGHT: 21px" id=IMG3 alt="" src="/_imgs/imagestrips/transparent_spacer.gif">&nbsp;
</LI>

<LI id=LI1 class="ms-crm-Menu" title=电子邮件知识库文章 tabIndex=-1 onclick=window.execScript(action) action="EmailArticle();">
<SPAN class="ms-crm-Menu-Label">
<A class="ms-crm-Menu-Label" tabIndex=-1 onClick="return false;" href="javascript:onclick();" target=_self>
<IMG class="ms-crm-Menu-ButtonFirst" tabIndex=-1 alt=电子邮件知识库文章 src="/_imgs/ico_16_138.gif">
<SPAN class="ms-crm-MenuItem-TextRTL" tabIndex=0>电子邮件知识库文章</SPAN>
</A>
</SPAN>
</LI>


</UL>
</TD>
<TD class="ms-crm-MenuBar-Items ms-crm-Menu-ICRight" noWrap>

<UL class="ms-crm-MenuBar-Right">
<LI accessKey=H id=help class="ms-crm-Menu" tabIndex=-1 menu="mnuhelp">
<SPAN class="ms-crm-Menu-Label">
<A class="ms-crm-Menu-Label" tabIndex=-1>
<IMG class="ms-crm-Menu-ButtonFirst" tabIndex=-1 alt="" src="/_imgs/ico/16_help.gif">
<SPAN class="ms-crm-MenuItem-Text" tabIndex=0>帮助(<U>H</U>)</SPAN>
<IMG style="CLIP: rect(0px 11px 16px 0px); BACKGROUND-IMAGE: url(/_imgs/imagestrips/control_imgs_1.gif); WIDTH: 11px; BACKGROUND-POSITION-Y: -32px; HEIGHT: 16px" id=IMG4 class="ms-crm-Menu-DownArrow" alt=更多 src="/_imgs/imagestrips/transparent_spacer.gif">
</A>

<A class="atLink" title=打开帮助(H)菜单的可访问表单 tabIndex=-1 onClick="return false;" href="javascript:onclick();" target=_self></A>
</SPAN>

<DIV style="DISPLAY: none">

<UL id=mnuhelp class="ms-crm-MenuList">
<LI id=mnu_helpOn class="ms-crm-MenuItem-Label" tabIndex=-1 key="P" action="loadHelp();">
<SPAN class="ms-crm-MenuItem-Label">
<A class="ms-crm-MenuLink" tabIndex=-1 onClick="return false;" href="javascript:onclick();" target=_self>
<SPAN class="ms-crm-MenuItem-Icon"></SPAN>
<SPAN class="ms-crm-MenuItem-Text" tabIndex=0>关于此页面的帮助(<U>P</U>)</SPAN>
</A>
</SPAN>
</LI>

<LI class="ms-crm-MenuList-Spacer" tabIndex=-1>
<HR class="ms-crm-MenuList-Spacer">
</LI>

<LI id=mnu_helpContent class="ms-crm-MenuItem-Label" tabIndex=-1 key="C" action="loadHelp('##WHATSNEW##');">
<SPAN class="ms-crm-MenuItem-Label">
<A class="ms-crm-MenuLink" tabIndex=-1 onClick="return false;" href="javascript:onclick();" target=_self>
<SPAN class="ms-crm-MenuItem-Icon"></SPAN><SPAN class="ms-crm-MenuItem-Text" tabIndex=0>目录(<U>C</U>)</SPAN>
</A>
</SPAN>
</LI>

<LI id=mnu_adminGuide class="ms-crm-MenuItem-Label" tabIndex=-1 key="G" action="loadHelp('##ADMINGUIDE##');">
<SPAN class="ms-crm-MenuItem-Label">
<A class="ms-crm-MenuLink" tabIndex=-1 onClick="return false;" href="javascript:onclick();" target=_self>
<SPAN class="ms-crm-MenuItem-Icon"></SPAN><SPAN class="ms-crm-MenuItem-Text" tabIndex=0>管理员指南(<U>G</U>)</SPAN>
</A>
</SPAN>
</LI>

<LI id=mnu_troubleShoot class="ms-crm-MenuItem-Label" tabIndex=-1 key="T" action="loadHelp('##TROUBLESHOOT##');">
<SPAN class="ms-crm-MenuItem-Label">
<A class="ms-crm-MenuLink" tabIndex=-1 onClick="return false;" href="javascript:onclick();" target=_self>
<SPAN class="ms-crm-MenuItem-Icon"></SPAN>
<SPAN class="ms-crm-MenuItem-Text" tabIndex=0>疑难解答(<U>T</U>)</SPAN>
</A>
</SPAN>
</LI>

<LI class="ms-crm-MenuList-Spacer" tabIndex=-1>
<HR class="ms-crm-MenuList-Spacer">
</LI>

<LI id=mnu_crmLive class="ms-crm-MenuItem-Label" tabIndex=-1 key="O" action="safeWindowOpen( 'http://go.microsoft.com/fwlink/?LinkId=35152&amp;clcid=0x804', 'MSCRMLive', 'width=790, height=500, menubar=1, toolbar=1, status=1, scrollbars=1, resizable=1');"><SPAN class="ms-crm-MenuItem-Label"><A class="ms-crm-MenuLink" tabIndex=-1 onClick="return false;" href="javascript:onclick();" target=_self><SPAN class="ms-crm-MenuItem-Icon"></SPAN><SPAN class="ms-crm-MenuItem-Text" tabIndex=0>Microsoft Dynamics CRM <U>O</U>nline(O)</SPAN></A></SPAN></LI>

<LI id=mnu_helpUpdates class="ms-crm-MenuItem-Label" tabIndex=-1 key="U" action="safeWindowOpen( 'http://go.microsoft.com/fwlink/?LinkId=76816', 'HelpUpdates', 'width=790, height=500, menubar=1, toolbar=1, status=1, scrollbars=1, resizable=1');"><SPAN class="ms-crm-MenuItem-Label"><A class="ms-crm-MenuLink" tabIndex=-1 onClick="return false;" href="javascript:onclick();" target=_self><SPAN class="ms-crm-MenuItem-Icon"></SPAN><SPAN class="ms-crm-MenuItem-Text" tabIndex=0>帮助更新(<U>U</U>)</SPAN></A></SPAN></LI>

<LI class="ms-crm-MenuList-Spacer" tabIndex=-1>
<HR class="ms-crm-MenuList-Spacer">
</LI>

<LI id=mnu_about class="ms-crm-MenuItem-Label" tabIndex=-1 key="A" action="openStdDlg('/about/default.aspx', 'MSCRMAbout', 570, 500)"><SPAN class="ms-crm-MenuItem-Label"><A class="ms-crm-MenuLink" tabIndex=-1 onClick="return false;" href="javascript:onclick();" target=_self><SPAN class="ms-crm-MenuItem-Icon"></SPAN><SPAN class="ms-crm-MenuItem-Text" tabIndex=0>关于 Microsoft Dynamics CRM(<U>A</U>)</SPAN></A></SPAN></LI>

</UL>

</DIV>

</LI>
</UL>

</TD>
</TR>
</TBODY>
</TABLE>

</body>
</html>

 

 

另外一种思路:

var barTopTableObj = document.getElementById("mnuBar1");
var ULObjs = barTopTableObj.getElementsByTagName("UL");
alert(ULObjs[0].childNodes.innerHTML);
var OperationManualObjs;
for (var n = 0; n < ULObjs[0].childNodes.length; n++) {
if (ULObjs[0].childNodes[n].id == "btnEmailArticle") {
OperationManualObjs = ULObjs[0].childNodes[n].cloneNode(true);
OperationManualObjs.id = "OperationManual";
OperationManualObjs.title = "系统操作手册";
OperationManualObjs.action = "window.open('/ISV/DownLoad/华宇万维维修系统操作手册.pdf')";
OperationManualObjs.childNodes[0].childNodes[0].childNodes[0].id = "ImageOM";
OperationManualObjs.childNodes[0].childNodes[0].childNodes[0].alt = "系统操作手册";
OperationManualObjs.childNodes[0].childNodes[0].childNodes[0].style.backgroundImage = "";
OperationManualObjs.childNodes[0].childNodes[0].childNodes[0].style.backgroundPositionY = "";
OperationManualObjs.childNodes[0].childNodes[0].childNodes[0].src = "/_imgs/ico/16_help.gif";
OperationManualObjs.childNodes[0].childNodes[0].childNodes[1].style.paddingTop = "3px";
OperationManualObjs.childNodes[0].childNodes[0].childNodes[1].align = "bottom";
OperationManualObjs.childNodes[0].childNodes[0].childNodes[1].innerHTML = "系统操作手册";
}
}
if (help != null) {
help.parentNode.insertBefore(OperationManualObjs, help.parentNode.lastChild);
help.style.display = "none";
}

 

 

替换已有的界面按钮:

 

var _MBcrmFormSubmitCrmForm59truetruefalse = document.getElementById("_MBcrmFormSubmitCrmForm59truetruefalse");
var ahtml = _MBcrmFormSubmitCrmForm59truetruefalse.getElementsByTagName("a");
ahtml[0].innerHTML = "<img tabIndex='0' class='ms-crm-Menu-ButtonFirst' alt='保存并新建' src='/_imgs/ico/16_L_saveOpen.gif'/>";
ahtml[0].innerHTML += "<span tabIndex='0' class='ms-crm-MenuItem-TextRTL'>保存并新建</span></a></span>";