0

My client is using d6 and views 3. They want to be able to display a box containing a random static image with an internal link to display in the same browser tab or an external link that would display in a new tab. I created a content type with a field to upload an image, a text field to include a url, and (for simplicity's sake) a text field to include the target (either _self or _blank). Then I built a views block to display each image using the 'rewrite the output of this field' option on the image field. The text for the rewrite looks something like this:

<a href="[field_link_value]" [field_target_value]>[field_image]</a>.

The problem I'm having is even when field_target_value has target="_self" in it, views or something is ignoring it and the a tag is always showing up in firebug with target="_blank". Another weird thing is that when I display the page source, the target doesn't appear at all. When you click on the image, it does in fact bring the page up in a different tab as expected.

I've looked in the views code and did not see anything in there that seems to be the cause. There is some custom code and theming on the site but I have not been able to find anything in there either.

Anyone have any clues why or thoughts on the strategy I am trying to use ??

2 Answers 2

0

Thank you for the suggestions. I ended up using the linkimagefield module and removing the rewrite from the view but it still showed the same behavior. I finally tracked it down as some javascript code originally added to check if the URL started with the letters http. If so, the link was treated as external and target='_blank' was added, overriding any other target attribute included. So this was ultimately not a drupal thing.

0

Print the results from the views template.you can rewrite the views template for that specific field and check the link that whether its external or internal using the drupal function url_is_external and you can add the attribute target="_blank" to those views fields that are external urls.

Off topic suggestion : if you want all external links on your website should open in new tab then you can use the extlink module to open all external links in new tabs.

External Links is a small module used to differentiate between internal and external links. Using jQuery, it will find all external links on a page and add an external icon indicating it will take you offsite or a mail icon for mailto: links.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.