Jump to content

Recommended Posts

Posted (edited)
Line 116

 

Find

 

Change to

 

Should work.

 

Thanks but, that didnt work when i was opening a word document.

 

Z

Edited by FN-GM
Posted

This is because your browser seems to have an embedded thing for word docs (eww).

 

IF what you're asking for is for a download prompt for the word document rather than have it appear in-browser, attempt the PHP below (passing in the path to the file and filename) and see what happens with that.

 

The header is what defines if the file downloads or if it shows up embedded in the browser, setting this up right (my script may need tweaking as necessary) will force a download rather than display it in-browser.

 

If you REALLY want the word document to show up in another window, you will need to ensure the link to it include target="_blank" as others have mentioned. I see no reason why this wouldn't work as the launch target is always triggered before the url in the href parameter is passed.

 

Here's my PHP Code for manually dishing up files. Be sure that this code is the ONLY thing that runs on a page (i.e. make a download.php and hook in the file to download e.g.: Download("c:\mydoc.txt","mydoc.txt");

 

Any whitespace that is additionally exported (or indeed any html) will corrupt the file.

 

function urlcode($stringname) {
   return str_replace(" ","%20",str_replace("'","%27",$stringname));
}

function Download($f_location,$f_name)
{
   header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
   header('Content-Description: File Transfer');
   header('Content-Type: application/octet-stream');
   header('Content-Length: ' . filesize($f_location));
 
   // MSIE doesn't play ball, it requires spaces to be %20  
if (eregi("MSIE",$_SERVER['HTTP_USER_AGENT'])) 
{
    header('Content-Disposition: attachment; filename="' . urlcode(basename($f_name)) . '"');	
	 
}   
else
{
    header('Content-Disposition: attachment; filename="' . basename($f_name) . '"');
   }
   readfile($f_location); 
}

Posted (edited)
I don't know if you care much about web standards and accessibility but the target attribute was deprecated in HTML 4.01.

 

What was it replaced with in HTML 4.01? I mean, the draft for HTML 5 appears to only have shown up today on the w3c.... So really pretty much most web browsers are gonna handle HTML 4.01 in the real world, and it is rare to fully remove deprecated functionality within two or three major versions.

Edited by Friez
Posted

The browser will handle it, certainly. He's running with a strict doctype though. :)

 

Just letting him know that he can't use the target attribute and XHTML 1.0 Strict if the page has to validate.

 

In my opinion, there never has been an acceptable replacement for it really and I think it's back in the XHTML 1.1 core spec. I find it's easiest to fall back to the Transitional doctype if the project has to pass validation.

Posted
What was it replaced with in HTML 4.01?

It wasn't. Javascript became the solution (and still is for a lot of folks)

 

eg:

 

newwindowlink.js

 

function initLinks() {
 for (i in document.links) {
   link = document.links[i];
   if (link.rel && link.rel.indexOf('external')!=-1) {
     link.onclick = onExternalLinkActivate;
     link.onkeypress = onExternalLinkActivate;
   }
 }
}

function onExternalLinkActivate() {
 window.open(this.href);
 return false;
}

window.onload = initLinks;

 

 

Declare in page HEAD with:

 

Then link becomes:

some site

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...