1

I have made my custom module in Drupal. I have a link that should open a popup window.

What arguments should I pass to l() so that the generated link would open a new popup window?

  • I just only want that my above link should be open in a pop up window – Mukesh Jun 3 '13 at 10:58
2

The link formatter function l() takes 3 arguments:

l($text, $path, array $options = array());

The $options array specifies the parameters to be passed to the link. One of them is $options['attributes'] which is itself an array and is used to specify the attributes of the anchor tag.

Use something like:

$options['attributes'] = array( 'target' => '_blank' );

when you are assembling the parameters to pass. This will open the link in a new window., which is the closest you can get with HTML.

For a real pop-up, you will have to add javascript to do the job, and adding something like:

$options['attributes'] = array( 'class' => 'popup' );

will give the javascript a target to use.

|improve this answer|||||
0

Have you looked at the External Link module? AFAICT there's no parameter for l() or even for url() that specifies a new window, but External Link provides additional behaviors that can be configured for external links.

|improve this answer|||||
0

You can use many widget as Dialog or Lightbox

In this case you need to add the attribute to the array

l(t('Link text'), 'open popup', array('attributes' => array('class' => array('YOUR-CLASS'))));

But you can add all the attribute you want, like target so:

l(t('Link text'), 'open popup', array('attributes' => array('target' => '_blank', 'class' => array ('your classes'), 'another_attr' => 'attr_val'));
|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.