CopyCode The Code is as follows: <! -- Menu style -->
<Style type = text/CSS>
. Cmenu {
Border-Right: #000000 1px solid;
Border-top: #000000 1px solid;
Font-weight: normal;
Font-size: 14px;
Visibility: hidden;
Border-left: #000000 1px solid;
Width: 150px;
Cursor: default;
Color: #000000;
Line-Height: 20px;
Border-bottom: #000000 1px solid;
Font-family: verdana, Arial, Helvetica, sans-serif;
Position: absolute;
Background-color: # eeeeff
}
. Menuitems {
Padding-Right: 5px;
Padding-left: 5px
}
</Style>
<Div class = cmenu id = "contextmenu" onmouseover = highlightmenu () onmouseout = lowlightmenu ()>
<Div class = menuitems clickcall = "alert ('view historical executions ');"> View historical executions </div>
<Div class = menuitems clickcall = "alert ('view annotation');"> View comments </div>
<Div class = menuitems clickcall = "alert ('insert/modify annotation');"> insert/modify comments </div>
<HR color = # aaaaaa size = "0">
<Div class = menuitems clickcall = "alert (' ');"> about </div>
</Div>
<SCRIPT type = "text/JavaScript">
VaR contextmenu = Document. getelementbyid ("contextmenu ");
Function getobjectname ()
{
Return document. getelementbyid ("cv. ID"). value;
}
Function getrvcontent ()
{
VaR objname = getobjectname ();
Return eval ("document. getelementbyid ('rvcontent" + objname + "');");
}
Function overwriterightclick () // rewrite the pop-up menu
{
VaR objname = getobjectname ();
Eval ("OCV" + objname + ". rvmainwnd. displaycontextmenu = displaycontextmenu ;");
}
Function disablerightclick ()
{
VaR objname = getobjectname ();
Eval ("OCV" + objname + ". bcanusecognosviewercontextmenu = false ;");
}
/* Menu-related function start */
Function displaycontextmenu (EVT ){
EVT = (EVT )? EVT: (event )? Event: NULL );
Hidecontextmenu ();
VaR rightedge = getrvcontent (). clientwidth-EVT. clientx;
VaR BottomEdge = getrvcontent (). clientheight-EVT. clienty;
If (rightedge <contextmenu. offsetwidth)
Contextmenu. style. Left = getrvcontent (). scrollleft + EVT. clientx-contextmenu. offsetwidth-getrvcontent (). offsetleft;
Else
Contextmenu. style. Left = getrvcontent (). scrollleft + EVT. clientx-getrvcontent (). offsetleft;
If (BottomEdge <contextmenu. offsetheight)
Contextmenu. style. Top = getrvcontent (). scrolltop + EVT. clienty-contextmenu. offsetheight-getrvcontent (). offsettop;
Else
Contextmenu. style. Top = getrvcontent (). scrolltop + EVT. clienty-getrvcontent (). offsettop;
Contextmenu. style. Visibility = "visible ";
Return false;
}
Function hidecontextmenu (){
VaR object = event. srcelement;
Contextmenu. style. Visibility = "hidden ";
If (object. classname = "menuitems "){
Eval (object. clickcall );
}
}
Function highlightmenu (){
VaR object = event. srcelement;
If (object. classname = "menuitems "){
Object. style. backgroundcolor = "highlight ";
Object. style. color = "white ";
}
}
Function lowlightmenu (){
VaR object = event. srcelement;
If (object. classname = "menuitems "){
Object. style. backgroundcolor = "";
Object. style. color = "black ";
}
}
/* Menu-related function end */
Overwriterightclick ();
Document. Body. onclick = hidecontextmenu;
</SCRIPT>
next I will introduce this Code. The style and Div above mainly define the Realistic Style of the menu. The referenced style is a clickcall attribute in the DIV of menuitems, this attribute is the JS function called when you click this menu item. You can change it to your own function. Here I just called alert.
the getobjectname function has a CV. ID object. Someone has asked this question before. What is "cv. ID" used? The names of the objects generated by running the Cognos report in reportstudio are different from those generated by using URL requests. However, the names of the objects generated by cognosviewer in the report generated by running the report in reportstudio are different, the cognosviewer object generated by the URL request is named ocv_ns _. You can view the source files of the two running results for comparison, which is more intuitive. It is found that the prefixes are the same (OCV), but the backend "Rs" and "_ NS _" are different. Many objects on the page use this rule, and the CV. ID is stored as the suffix. In this way, you can piece together the object names in the current running mode.
the getrvcontent function obtains the DIV object whose ID is rvcontent_ns _ or rvcontentrs. The rvcontent function displays the report content defined by reportstudio, excluding the cognosviewer toolbar and title bar.
the overwriterightclick function is to change the function called by right-clicking Cognos to its own defined function.
the disablerightclick function has already been used to disable the right-click menu.
functions such as displaycontextmenu, hidecontextmenu, highlightmenu, and lowlightmenu are first related to menu operations and can be transformed according to actual requirements.
as follows: