Hola compañeros, necesito meter un comando onclick en un enlace del menu subs.php.
En concreto este código: onclick="window.open(this.href, this.target, 'width=580,height=430');
Para que al hacer click abra una ventana nueva, ¿es posible? saludos y gracias ;)
Personalmente considero que SMF es una maraña de código todo desordenado, y por esta razón es muy dificil customizarlo correctamente sin hacer uso de "hacks" algo ortodoxos. Sin embargo, si tu desesperación es tal, puedes considerar lo siguiente.
Tienes esto en el Sources/Subs.php:
'sub_buttons' => array(
'mlist_view' => array(
'title' => $txt['mlist_menu_view'],
'href' => $scripturl . '?action=mlist',
Y esto en Theme/{tema}/index.template:
<a href="', $childbutton['href'], '"', isset($childbutton['target']) ? ' target="' . $childbutton['target'] . '"' : '', '>
Entonces, podemos deducir que hacer algo como esto en el Sources/Subs.php debería solucionar tu problema:
'sub_buttons' => array(
'mlist_view' => array(
'title' => $txt['mlist_menu_view'],
'href' => $scripturl . '?action=mlist',
'onclick' => "window.open(this.href, this.target, 'width=580,height=430');"
Y editar el Theme/{tema}/index.template para dejarlo así:
<a href="', $childbutton['href'], '"', isset($childbutton['onclick']) ? ' onclick="' . $childbutton['onclick'] . '"' : '', '>
Gracias por interesarte por el tema.
El código no funciona, quiero insertarlo en el menu principal, tengo hecho lo siguiente:
'radio' => array(
'title' => 'Radio',
'href' => '/radio',
'onclick' => "'window.open(this.href, this.target, 'width=580,height=430'",
'show' => true,
'sub_buttons' => array(
),
),
Quiero que dicha radio se abra en una ventana nueva al hacer on click, ya que es una radio y quiero que este sonando aunque naveguen por otras páginas ;)
Lo que te indico manfred estaria casi bien, solo que tiene unos detalles.
1º No cierra la variable en el subs.php
2º El codigo que te indico en el index.template es para los sub-botones y no para los botones.
3º No le puso return false, con lo que al abrirte el popup tambien te abriria la misma pagina en la ventana actual.
Los cambios serian mas o menos asi:
En el subs.php vas a agregar esto:
'radio' => array(
'title' => 'Radio',
'href' => '/radio',
'onclick' => "window.open(this.href, this.target, 'width=580,height=430'); return false;",
'show' => true,
'sub_buttons' => array(
),
),
Donde dice /radio tenes que poner una ruta real, eso te dara errores. pone la ruta exacta del link.
En el index.template.php
busca esto:
<a class="', $button['active_button'] ? 'active ' : '', 'firstlevel" href="', $button['href'], '"', isset($button['target']) ? ' target="' . $button['target'] . '"' : '', '>
Reemplazalo con esto:
<a ', isset($button['onclick']) ? ' onclick="' . $button['onclick'] . '"' : '', ' class="', $button['active_button'] ? 'active ' : '', 'firstlevel" href="', $button['href'], '"', isset($button['target']) ? ' target="' . $button['target'] . '"' : '', '>
Espero que te sirva.
Saludos