I’m working with this idea: get href onclick and redirect with link Because i need a link redirect to another page.
My problem is that the second page is dinamic. For it, i use a shortcode. But im not know how i can do for it works. The var yourHTML is not working.
<?php function links_redirect() { global $activities_template, $bp;$activity_id; $activity_id = bp_get_activity_id(); $user_id = bp_get_activity_user_id(); $redirectLink= $user_id. '/test/' . $activity_id; return $redirectLink; } add_shortcode('link_shortcode', 'links_redirect'); ?> <script> function abc(event) { var yourHTML = '<?php do_shortcode("[link_shortcode]"); ?>'; var href = event.currentTarget.getAttribute('href'); window.location='example.com?ver=' + yourHTML; } </script> <a id="first" onclick='abc(event);' href="<?php echo $variblefuncionando;?>" >Ver</a>
Advertisement
Answer
You should use event.preventDefault();
to cancel the default redirection
function abc(event) { event.preventDefault(); ..... }