Jump to content
johnnydoe

Opening links to files automatically in new tab

Recommended Posts

Hi there!

With the module "Page Edit Link" I can make settings so that links to external websites open in a new tab automatically, which is very handy. Now I want to do the same with links that point to files, so that the files (jpgs and pdfs) are opened in a new tab too. It seems not to be possible with "Page Edit Link". Is there another way? I know, the page editors could set the "_blank" value each time manually, but this doesn't seem to be very efficient to me. Any ideas?

Thanks in advance!
Jonas

Share this post


Link to post
Share on other sites

Was literally thinking about the same thing just yesterday. Solved it by a combination of JavaScript targeting only links to assets and instructing users to apply target "_self" to file links they don't want to open in a new window/tab. That's definitely less intuitive than having target "_blank" automatically selected, but does the trick :)

Another option would be injecting JavaScript for when Page Edit Link is rendered and handling this there. In that case it would probably make sense to track the change event of the file input and act on that, perhaps combined with a check that avoids changing the target value if the user has already changed it manually.

Just for the record, it would be nice to see a built-in setting for this. I'd assume this to be a relatively common need.

  • Like 1

Share this post


Link to post
Share on other sites

Hi teppo, thanks for your reply! I now took the javascript road. With jQuery I search for all links which have 'assets/files' in their href and attach target="_blank" to them. 

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...