Question

How to add custom html buttons opening 3rd party websites on clicks?

Followed some tutorials, but such code wont work for me:

        'customCode' => '{literal}<input id="Button" title="Button" class="button" type="button" name="Button" value="Some Button" onClick="window.open("http://google.com","","width=800,height=600");">{/literal}',
        'sugar_html' =>
          array (
            'type' => 'button',
            'value' => 'Button',
            'htmlOptions' =>
              array (
                'class' => 'button',
                'id' => 'Button',
                'title' => 'Button',
                'onclick' => 'window.open("http://google.com","","width=800,height=600");',
                'name' => 'Button',
              ),
          ),

It will split '' strings by ". Like http will be treated as input property! Tryied all sorts of character escapes, all they do is change what is treated as property and what as value. Not once I got that URL intact.

Was it helpful?

Solution

Pretty sure you're on the right track. Instead of this

'customCode' => '{literal}<input id="Button" title="Button" class="button" type="button" name="Button" value="Some Button" onClick="window.open("http://google.com","","width=800,height=600");">{/literal}',

Try this

'customCode' => '{literal}<input id="Button" title="Button" class="button" type="button" name="Button" value="Some Button" onClick="window.open(\'http://google.com\',\'\',\'width=800,height=600\');">{/literal}',

The difference being the mixed quotes... you had double quotes embedded in double quotes. Instead, use escaped single quotes inside of them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top