open uploaded PDF file in NEW Window

Events happening in the community are now at Drupal community events on www.drupal.org.
CherylJoy's picture

Looking for a work around to have my PDF files, which are uploaded through the attach file, to open in a New Window
I found this node
https://www.drupal.org/node/301234#comment-4764468
Using Drupal 7

27 seems to be the answer however I do not seem to be able to make it work

It says to edit this in the php code when you insert it.
function THEMENAME_file_link($variables)

THEMENAME I think should be the machine name of your theme.
How do I find this?
If a theme is based on another theme which template.php would I edit.

thanks in advance
Cheryl

Comments

If a theme is based on

c13l0's picture

If a theme is based on another theme which template.php would I edit.

You will edit template.php inside of your sub-theme. You can find your sub-theme at /sites/all/themes/yoursubtheme

It says to edit this in the php code when you insert it.
function THEMENAME_file_link($variables)

THEMENAME will be the name of your sub-theme

Thanks Cielo Was worth a

CherylJoy's picture

Thanks Cielo

Was worth a try...did not work.
Cheryl

extlink

ckosloff's picture

try the extlink module https://www.drupal.org/project/extlink.
You can treat a pdf as an external link and have it open in a new window, it will do all sorts of nifty things for your mailtos too.
Follow the instructions and you should not have to mess up anything in Drupal internals.

once extlink enabled, you

ckosloff's picture

once extlink enabled, you have to add a new field to your content type.
Name: pdf
machine name: your_content_type_pdf
type: file
widget: file
Save
You don't need to make this field required.
This will add a button to your form for creating new content of that type.
You upload a pdf from your computer.
Go to Structure -> Content types -> Your_type (Manage display) -> Full content, make sure that pdf field is not hidden, drag it to where you want it to be
Go to Configuration -> User interface -> External links
Options to enable are self-explanatory, you want open in a new window enabled.
The only thing to modify is the tab Pattern Matching at the bottom, add this: .pdf
Save.
Your pdf will open in a new window, plus you will have nifty icons for your ext links.
Credit goes to the Forcontu Drupal course.

There is an escape character

ckosloff's picture

There is an escape character (backslash) before the .pdf, make sure that you enter it in your Pattern Matching tab, Drupal site does not display it, cannot show it.

module pdf

CherylJoy's picture

thank you..
will do this later today...I DO appreciate your help

You could also perhaps

bhosmer's picture

You could also perhaps accomplish this with some apache rewrites and or by changing the mime types.

I've never used File Field Target, but it looks promising as well.

I would be careful though not to annoy your users. Chrome for example will open pdfs automatically in the browser. Personally, I hate sites that force a targe="blank" because then I end up with a new tab that I just have to close instead of just hitting the back button.

Sometimes less is more.

Florida

Group organizers

Group categories

Florida Topics

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: