简体   繁体   中英

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.

edit: I just found out even I tried to open a html page instead of a pdf, it still happened

This is because the browser replaces the current document with whatever the expression javascript:... evaluates to. In this case, the returned value is an object representing the opened window, which becomes [object Object] (or something similar) when displayed as text. 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 ) :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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