HTML : Anyone know how to get a .PDF file to open in a new browser window?.

You've lost me!!??. :p

I've got a .pdf I have uploaded to my server that I need web viewers to be able to open from a website page from a hyperlink, in a new browser window. The way I have it just now either opens it, but not in a new window ( replaces the webpage they were on ) or it opens it in a new window but for some strange reason the webpage it has opened from jumps from that page back to my /index.html page?. :confused:
 
Have you tried
Code:
<a href="pdfurl.pdf" target="_blank">Link</a>

That's all you should need

Yeah, that works, ta. I was kinda trying to avoid using "target" as its deprecated but I'm not that fussed, my doctype is Transitional anyhow.

Thanks, Jonny_no2. :)
 
Yeah, but unfortunately there's not an equivalent in xhtml, you could use a javascript work around. (Edit - as above :p)

target is a valid attribute in html5 though so you are future proof using it ;)
 
Cheers folks, top stuff. I'll look into the .js method, "target" will do fine for now.

Thanks for the info guys. :)
 
Cheers folks, top stuff. I'll look into the .js method, "target" will do fine for now.

Thanks for the info guys. :)

the rel external is the xhtml way of doing of things, but weirdly does require js to actually make the thing work as you want :)
 
Just use <a href="whatever.pdf" onclick="window.open(this.href); return false;">
This is the method I use. It relies on jQuery, but 99% of the sites I create have it anyway.

JS
Code:
$(function() {
    $("a[rel='external']").click(function(e) {
        window.open($(this).attr("href"));
        e.preventDefault();
    });
});

HTML
Code:
<a href="whatever.pdf" rel="external">Download me</a>
 
Back
Top Bottom