hi there,
using this PHP script how can i make it so documents open in a new windows please?
thanks
Printable View
hi there,
using this PHP script how can i make it so documents open in a new windows please?
thanks
Line 116
Find
Change toCode:<a href="'+f['url']+'">
Should work.Code:<a href="'+f['url']+'" target="_blank">
when you generate the html link are you including
target="_blank"
in the a href tag?
I don't know if you care much about web standards and accessibility but the target attribute was deprecated in HTML 4.01.
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.
PHP Code: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);
}
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.
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.
It wasn't. Javascript became the solution (and still is for a lot of folks)Quote:
What was it replaced with in HTML 4.01?
eg:
newwindowlink.js
Code: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:Code:<script src="newwindowlink.js" type="text/javascript"></script>
Code:<a href="http://site.com" rel="external">some site</a>