Javascript 参数化Onclick函数在IE中不起作用
我想在点击chrome中的pdf链接时显示打印弹出窗口,并想在IE和FF中打开pdf选项卡。我的代码在FF和chrome中运行良好,但在IE中运行时,显示函数printObjectPdf()未定义。请帮忙 这是我的代码Javascript 参数化Onclick函数在IE中不起作用,javascript,html,dom,Javascript,Html,Dom,我想在点击chrome中的pdf链接时显示打印弹出窗口,并想在IE和FF中打开pdf选项卡。我的代码在FF和chrome中运行良好,但在IE中运行时,显示函数printObjectPdf()未定义。请帮忙 这是我的代码 <style type="text/css"> @media print { .dontprint{display:none} } </style> <sc
<style type="text/css">
@media print
{
.dontprint{display:none}
}
</style>
<script type="text/javascript">
function printIframePdf(iframeId=''){
alert(iframeId);
window.frames[iframeId].focus();
try {
window.frames[iframeId].print();
}
catch(e){
window.print();
console.log(e);
}
}
function printObjectPdf(iframeId='') {
try{
document.getElementById('idPdf').Print();
}
catch(e){
if( navigator.userAgent.toLowerCase().indexOf('chrome') > -1 ){
printIframePdf(iframeId);
}else{
var url = document.getElementById(iframeId).src;
window.open(url, '_blank');
}
}
}
function idPdf_onreadystatechange() {
if (idPdf.readyState === 4)
setTimeout(printObjectPdf(iframeId), 1000);
}
</script>
<div class="dontprint" >
<form><input type="button" onClick="printObjectPdf('printf1')" class="btn" value="Print"/></form>
<form><input type="button" onClick="printObjectPdf('printf2')" class="btn" value="Print"/></form>
</div>
<iframe id="printf1" name="printf1" src="http://localhost/PDFtest/Device-Details.pdf" frameborder="0" width="440" height="580" style="width: 440px; height: 580px;display: none;"></iframe>
<iframe id="printf2" name="printf2" src="http://localhost/PDFtest/Prod-Support-Material.pdf" frameborder="0" width="440" height="580" style="width: 440px; height: 580px;display: none;"></iframe>
@媒体印刷品
{
.dontprint{display:none}
}
函数printIframePdf(iframeId=''){
警报(iframeId);
frames[iframeId].focus();
试一试{
frames[iframeId].print();
}
捕获(e){
window.print();
控制台日志(e);
}
}
函数printObjectPdf(iframeId=''){
试试{
document.getElementById('idPdf').Print();
}
捕获(e){
if(navigator.userAgent.toLowerCase().indexOf('chrome')>-1){
printIframePdf(iframeId);
}否则{
var url=document.getElementById(iframeId).src;
打开(url,“U空白”);
}
}
}
函数idPdf_onreadystatechange(){
如果(idPdf.readyState==4)
setTimeout(printObjectPdf(iframeId),1000);
}