Execute link using javascript

六月ゝ 毕业季﹏ 提交于 2019-12-13 19:10:55

问题


The following link opens a video when clicked:

<a href="<?php echo  $rows['image1'] ; ?> " rel="vidbox" title="<?php  echo  $rows['name']."          <br>".nl2br($rows['detail']) ; ?>" id="m2"><?php echo  $rows['name'] ; ?></a>

Can I run/execute this link using Javascript/PHP as if someone clicked on this link?


回答1:


It is not possible to click on a link using javascript / jquery. You can trigger the bound events using $('#m2').click() but it will not open the url. What you could do is, use document.location.href to open the page

document.location.href = document.getElementById('m2').href;



回答2:


Try this if you are using jQuery.

$(document).ready(function(){
    $('#m2').click();
});

Where m2 is the ID of the link to be clicked.



来源:https://stackoverflow.com/questions/11498101/execute-link-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!