具有Javascript功能的Href在右键单击时不显示“目标另存为”

时间:2015-06-22 18:26:07

标签: javascript function

下面是我的jsp页面上的链接:

<td  height="37" align="right">
    <a  href="javascript:getPolicyPaper('/cpi/producer/CSPDocumentGateway?jadeAction=MCS02&<%= MCSUIKeys.ASP_MCS_DOCUMENT_SELECTED %>=<%= i %>&m=<%=aView.getCalMonth()%>&y=<%=aView.getCalYear()%>&p=<%=aView.getProducerNumber()%>', 'pdf', '640','550')">DOC</a>
</td>

Javascript功能:

function getPolicyPaper(policyPaperUrl,policyType,windowWidth,windowHeight) {
//Calculate center of screen
var winWidth = windowWidth;
var winHeight = windowHeight;
var policyElement = policyType;
var xPos = (screen.availWidth-winWidth)/2;
var yPos = (screen.availHeight-winHeight)/2;
attrib = "hotkeys=true,menubar=no,personalbar=no,titlebar=yes,toolbar=no,location=no,top=" + yPos + ",left=" + xPos + ",width=" + winWidth + ",height=" + winHeight +",resizable=yes,scrollbars=no";
new_window= window.open(policyPaperUrl, policyElement, attrib);
new_window.focus();

}

当我右键点击IE8中的“DOC”链接时,它现在会显示“目标另存为”选项。我需要为用户提供右键单击和保存此pdf文档的选项。

1 个答案:

答案 0 :(得分:1)

您可以将网址格式化为:

 <a href="/cpi/producer/CSPDocumentGateway?jadeAction=MCS02&<%= MCSUIKeys.ASP_MCS_DOCUMENT_SELECTED %>=<%= i %>&m=<%=aView.getCalMonth()%>&y=<%=aView.getCalYear()%>&p=<%=aView.getProducerNumber()%>' onclick="getPolicyPaper(this.href, 'pdf', '640','550'); return false;">DOC</a>

更好的方法是将JS处理程序移动到事件侦听器中。