0

I have a views jump-menu of PDFs. I'd like the PDF to open in a new window when the user clicks the "go" button on the view.

I've tried using javascript to set the form's target attribute to _blank. It is showing in the markup, but it has no effect on the behavior of the form submission.

Any ideas on how to do this?

| improve this question | | | | |
1

The only way I've found to do this so far is to alter the ctools jumpMenu behaviour with the following JS. This is probably a lot more code than I need, but it seems to do the job. Better answers are appreciated.

JS

// place this outside your .ready() function
Drupal.behaviors.CToolsJumpMenu = {
   attach: function(context) {
     $('.ctools-jump-menu-hide:not(.ctools-jump-menu-processed)')
       .addClass('ctools-jump-menu-processed')
       .hide();

     $('.ctools-jump-menu-change:not(.ctools-jump-menu-processed)')
       .addClass('ctools-jump-menu-processed')
       .change(function() {
         var loc = $(this).val();
         if (loc) {
           location.href = loc;
         }
         return false;
       });

     $('.ctools-jump-menu-button:not(.ctools-jump-menu-processed)')
       .addClass('ctools-jump-menu-processed')
       .click(function() {
         // Instead of submitting the form, just perform the redirect.

         // Find our sibling value.
         var $select = $(this).parents('form').find('.ctools-jump-menu-select');
         var loc = $select.val();
         if (loc) {
          // console.log(loc.slice(loc.indexOf('::') +2) );
           // location.href = loc.slice(loc.indexOf('::') +2);
           window.open(loc));
         }
         return false;
       });
   }
 }

Source

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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