Download & Extend

Using generic fields display, can the link to the file open in new window?

Project:FileField
Version:6.x-3.10
Component:User interface
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

What's the simplest way to get the file field to open in a new window when the link is using the description text? I can only seem to get it to target="_blank" when I display the full URL.

Comments

#1

I am using a view to show the field, so maybe there are more options available there with theming?

#2

You may use the External Links module. You can configure the module's pattern matching field to match your files that should be opened in a new window. For example, to open all PDF documents in a new window, you can set the "Include patterns matching" field to the following:
.*\.pdf

#3

If you're using Views, you can use the "Rewrite results" option for that field. I forget how it's worded in D6, but it's one of the options in the field configuration. Check the box that says "Rewrite the output of this field" and the one that says "Output this field as a link" and you'll get a bunch of link settings, including target.

However, I appreciate the tip given in comment #2 because I'm working on a D7 site and wanted to set the link target for a file field but I'm not using Views and I preferred to avoid using Display Suite because it's a PITA to get it working with a Rate widget. The External Links module and pattern-matching took 5 seconds to set up, much easier. Thanks!

#4

I'm having the same issue in D7.
This may be ill-advised but if you like you can change the module/file/file.module file to add target="_blank" to all generic file links. Not wanting to install another module to open links in new windows I just changed the file directly. On my version I modified this, starting at line 734:
'type' => $file->filemime . '; length=' . $file->filesize,
),

to this
'type' => $file->filemime . '; length=' . $file->filesize,
'target' => '_blank',
),

Works for me so far.

#5

Status:active» closed (fixed)

This may be ill-advised but if you like you can change the module/file/file.module file to add target="_blank" to all generic file links.

It's ill-advised because you could easily accomplish your goal by copy/pasting the theme function you want to override into your theme's template.php. That way you can upgrade the module later and your theme contains the customizations. In this case, I think you would want to override theme_filefield_file(). See Overriding theme functions in the Drupal handbook.