Uutiset:

Wondering if this will always be free?  See why free is better.

Main Menu
Advertisement:

Adding onClick to main button array

Aloittaja Krashsite, lokakuu 03, 2013, 05:19:55 IP

« edellinen - seuraava »

Sir Osis of Liver


Tinkering with this, and curious if it's possible to do something similar in the main menu button array in Subs.php.  Tried adding this to the array -



     'custom' => 'onclick="return confirm(\'Are you sure?\');"',



but it's ignored.

When in Emor, do as the Snamors.
                              - D. Lister

Arantor

There is a way you can do it but you're not supposed to do it, really :P

If you adjust the target to be
'target' => 'http://example.com" onclick="return confirm(\'Are you sure?\');',

it should work. The surrounding " will be added normally to start the link and end the onclick.
Holder of controversial views, all of which my own.


Sir Osis of Liver


Tried this -



'target' => 'http://www.simplemachines.org" onclick="return confirm(\'Are you sure?\');',



Shows the confirm box, but opens new blank window when click 'OK'.

And why does it require a single quote before the url, and double quote after?

When in Emor, do as the Snamors.
                              - D. Lister

Sir Osis of Liver


Ok, it was missing a double quote at the end, now it opens the page in a new window, should be _self.



'target' => $scripturl . '?action=help" onclick="return confirm(\'Are you sure?\');"',



When in Emor, do as the Snamors.
                              - D. Lister

Arantor

 Bah, it's not *target*, it's the normal href attribute (target is for something else unrelated)

As for the mismatch of quotes, I did actually explain that. But I guess I can be more thorough.

When it's output, it's output as an <a href="{href goes here}"> link. You already have the surrounding ", what this is doing is exiting the " for the href, and starting a new one.

So: <a href="{href goes here}"> becomes:

<a href="http://example.com/" onclick="return confirm('Are you sure?');"> because of the quote handling.

And no, it wasn't missing a double quote.
Holder of controversial views, all of which my own.


Sir Osis of Liver

I'll try that.  Meanwhile, this works -



'help' => array(
'title' => $txt['help'],
'href' => $scripturl . '?action=help',
'target' => '_self" onclick="return confirm(\'Are you sure?\');"',
'show' => true,
'sub_buttons' => array(
),
),



Looks like it shouldn't, but .

When in Emor, do as the Snamors.
                              - D. Lister

Arantor

Except it adds an extra " into your code that shouldn't be there. Look at the result source, you should find you have an extra " in there (for the very reason I outlined)
Holder of controversial views, all of which my own.


Sir Osis of Liver


Works either way, so I took out the '' on the end.



'target' => '_self" onclick="return confirm(\'Are you sure?\');',



How to you put it in the 'href' field?

When in Emor, do as the Snamors.
                              - D. Lister

Arantor

Same way you do anything else...

'href' => $scripturl . '?action=help" onclick="return confirm(\'Are you sure?\');',
Holder of controversial views, all of which my own.


Sir Osis of Liver


Ok, much cleaner. Had tried that, but didn't get the quotes right.

Thx.

When in Emor, do as the Snamors.
                              - D. Lister

Advertisement: