Execute link using javascript

2019-07-26 16:24发布

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?

2条回答
女痞
2楼-- · 2019-07-26 17:04

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;
查看更多
闹够了就滚
3楼-- · 2019-07-26 17:20

Try this if you are using jQuery.

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

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

查看更多
登录 后发表回答