添加、删除SVG Viewer的主菜单项(例子中是添加一个“粘贴”项,并将“放大显示”菜单项删除。) Adobe SVG Viewer 3.03 + IE6下测试通过。 代码如下: <?xml version="1.0" encoding="utf-8" standalone="no" ?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" οnlοad="init(evt)"> <mce:script type="text/javascript"><!-- var svgDoc = null ; var svgRoot = null ; function init(evt) { svgDoc = evt.target.ownerDocument ; svgRoot = svgDoc.documentElement ; AlterMainMenu() ; } function Paste() { alert('paste') ; } //修改主菜单项,这里主要就是添加一些菜单项 function AlterMainMenu() { var menu = contextMenu.firstChild.firstChild ; //获取SVG Viewer的主菜单 var item = null ; var text = null ; for(; menu; menu = menu.nextSibling) //遍历菜单项,直到找到“放大显示”的菜单项 { if(menu.nodeType == 3 || menu.nodeType == 8 || menu.getAttribute('id') != 'ZoomIn') continue ; //添加一个“粘贴”的菜单项 item = contextMenu.createElement('item') ; item.setAttribute('id', 'paste') ; item.setAttribute('onactivate', 'Paste()') ; //单击“粘贴”菜单项时,调用Paste()函数 text = contextMenu.createTextNode('粘贴') ; item.appendChild(text) ; contextMenu.firstChild.insertBefore(item, menu) ; //将“粘贴”菜单项加入主菜单 contextMenu.firstChild.removeChild(menu) ; //同时删除“放大显示”菜单项 break ; } } // --></mce:script> <rect id="background" x="0" y="0" width="100%" height="100%" fill="gray" /> </svg> 效果图: