• Resolved simbian

    (@simbian)


    Hello, i had setup a simple message (with no button) with a link:

    <a href="#" onclick="if(window.__lxG__consent__!==undefined&&window.__lxG__consent__.getState()!==null){window.__lxG__consent__.showConsent()} else {alert('This function only for users from European Economic Area (EEA)')}; return false">Change privacy settings</a>

    but it doesn’t work, i looked at source code and the HTML is rendered without onclick so only the link to #.

    Is this a bug?

    Another question: if i would use the button to show, how can i implement the link above?

    Thanks in advice.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author wpexplorer

    (@wpexplorer)

    Hi,

    This is AJ the theme author. For security reasons the plugin strips out any scripts from the customizer fields (this is very important). Rather then adding an inline script directly in the customizer what you’ll want to do is add the javascript to your site and then target the link.

    If you are using a child theme the code would be added in your child theme’s functions.php file. If not, you would want to use some sort of “code snippets” plugin such as WPCode or Code Snippets.

    Since you will be targeting the link/button with custom javascript you can of course use the included button if you’d like.

    Here is what your code may look like for use with the included button:

    add_action( 'wp_footer', function() { ?>
    	<script>
    		document.addEventListener( 'click', event => {
    			if ( ! event.target.closest( '.easy-notification-bar-button a' ) ) {
    				return;
    			}
    			if ( window.__lxG__consent__ !== undefined && window.__lxG__consent__.getState() !== null ) {
    				window.__lxG__consent__.showConsent();
    			} else {
    				alert( 'This function only for users from European Economic Area (EEA)' );
    			};
    			event.preventDefault();
    		} );
    	</script>
    <?php } );
    • AJ
    • This reply was modified 1 year, 5 months ago by wpexplorer.
    Thread Starter simbian

    (@simbian)

    Hello, ok thanks for explanation.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Onclick event not working’ is closed to new replies.