By ElectricStudio.co.uk on
Hi
Can some one please tell me what file I need to change to add a target for the file attachment links? Currently the attachment open up in the same window, but my client has requested to have them opening in a separate window.
In what file can I add the target="_blank" tag to the a href link for a uploaded, attached file?
Thank you for any help or advice. I'm using Drupal 5.1
Comments
Same question
I have the same request. Please tell me what is the solution for this problem.
Launch all http: on a new page
I'm not sure this is what you were looking for but basically, the below syntax will launch all http url address (url that started with http:) in a new browser:
1. Create a new template.php (or edit it if it was already there) --> under your themes folder (e.g themes/bluemarines)
2. Type in the followings:
<? php
function phptemplate_menu_item_link($item, $link_item) {
if (substr($link_item['path'], 0, 4) == 'http') {
return l($item['title'], $link_item['path'], !empty($item['description']) ? array('title' => $item['description'], 'target' => '_blank') : array('target' => '_blank'), isset($item['query']) ? $item['query'] : NULL);
}
else {
return l($item['title'], $link_item['path'], !empty($item['description']) ? array('title' => $item['description']) : array(), isset($item['query']) ? $item['query'] : NULL);
}
}
? >
Once again, I'm not sure this will fit with what you were trying to do...
Thanks trantt
but it isn't good for me, and - I think - it not works.
So, I want to open a blank page when I click on an attachment. So the attachments "a" tag have to have a target:"_blank" option.
I'm new in drupal and in php programming, so sorry for my stupid questions. (And for my bad english too... :()
I hope this time it is clearlier.
Thank you for your suggestion
Thank you for your suggestion, but can I ask you if you know where the link is being generated form in the first place?
Sorry, but I don't know, but
Sorry, but I don't know, but I also need it. So I'm looking for it too...
It is in the upload.module
I am using 4.7.6 but I am guessing there is something similar in 5.1.
In upload.module, you can add attributes to the link in the attachments table. The core code is:
and you will have to change it to
I hope this helps in the 5.1 world.
Certanly does.
I'm surprised this option isn't in the module. I can't remember the last time I created a link without _blank target...!
It works.
I'm using the solution from http://drupal.org/node/190035 for RSS to open in a new window.
All of my external links open in a new page!
And it works with Drupal versions 5.1 , 5.3 and 5.5
https://kloebb.nl and https://noww.nl
how about 6.2
I'm trying to add the _blank to one of my primary links in Drupal 6.2
I too
That code snippet above makes sense. However it doesn't seem to have an effect on my attachment hook.
Via Upload Attachement Override
This worked for me:
Add the following code into the template.php file of your theme. This is based on the code from bottdev in the post above, but updated for drupal 6. The key in the update is that passing attributes to the link function has been modified. See api for function l().
Worked like a charm, as-is.
Worked like a charm, as-is. thanks!
CCK Fields
This is great and works perfectly. Do you have any suggestions on how I could apply it to CCK file fields that I've uploaded?
Because those files weren't uploaded with the upload module the code as written isn't applied. I'm thinking there must be an easy way to modify the code to get it to apply to those fields as well.
All help appreciated!
Cheers,
works for other attributes too.
This ("Via Upload Attachment Override") works for other attributes too, such as rel="lightbox".
There is a module external
There is a module external links that solves this problem. In the site config part there is option to open all links in new window. Works in 5 and 6
Does not work for internal links
Nice little module, but it is just for external links. Attachments are internal links, thus this module has no effect there.