简体   繁体   English

在IE9中在新窗口中打开pdf无效

[英]Open a pdf in new windows in IE9 doesn't work

I used this code 我用了这段代码

<a href="javascript:window.open('../../files/registration/2013CRNNS_GuideforLicenceRenewalApplication.pdf','1','width=750,height=900')" >

to open a pdf in a new window which works fine in chrome, but when I tried it in IE9, the pdf file still opened, but the parent window became blank with only a [object] on it. 在新的窗口中打开pdf,该窗口在chrome中可以正常工作,但是当我在IE9中尝试使用pdf时,仍然打开了pdf文件,但父窗口变成空白,只有[object]

edit: I just found out even I tried to open a html page instead of a pdf, it still happened 编辑:我什至发现即使我试图打开一个html页面而不是pdf,它仍然发生

This is because the browser replaces the current document with whatever the expression javascript:... evaluates to. 这是因为浏览器会用javascript:...计算得出的表达式替换当前文档。 In this case, the returned value is an object representing the opened window, which becomes [object Object] (or something similar) when displayed as text. 在这种情况下,返回值是一个代表打开的窗口的对象,当显示为文本时,该[object Object]变为[object Object] (或类似的[object Object] )。 In order to avoid that, you should always use the void operator, which just discards its operand (technically, the void operator evaluates its operand, and returns undefined ) : 为了避免这种情况,您应该始终使用void运算符,该运算符会丢弃其操作数(从技术上讲, void运算符会评估其操作数,并返回undefined ):

<a href="javascript:void window.open(....)">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM