[英]Get href on click and redirect with shortcode
I'm working with this idea: get href onclick and redirect with link Because i need a link redirect to another page.我正在使用这个想法: 获取 href onclick 并使用链接重定向因为我需要链接重定向到另一个页面。
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.
var yourHTML 不起作用。
<?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>
You should use event.preventDefault();
你应该使用
event.preventDefault();
to cancel the default redirection取消默认重定向
function abc(event) {
event.preventDefault();
.....
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.