js与jquery自动触发a链接的方法

admin4年前前端技术1011

自动触发a链接的方法如下:

1.

<body >
 <a  href="http://www.shengmake.net" ><span>Affiliate</span></a> 
</body>
<script src="jquery-3.6.0.min.js"></script>

<script type="text/javascript">
 $(document).ready(function() {
     setTimeout(function() {
  $("span").click();
    }, 1000);
  
 
 });
 
</script>



2.

<script type="text/javascript">
var lianjie="http://www.shengmake.net";
var aa = document.createElement("a");
aa.setAttribute("href", lianjie);
// aa.setAttribute("target", "_blank");
var bodys = document.getElementsByTagName("body")[0];
bodys.appendChild(aa);
aa.click();
</script>


关键知识点:不能设置target属性为_blank否则会被浏览器拦截


相关文章

原生javascrip 复制功能

兼容chrome FIrfox IE 下载地址000.zip代码如下:<!DOCTYPE html> <html> <head> &nbs...

jquery默认设置第一个类的css或者属性

var me=$("#cima>input");me.eq(0).css...

whatsapp浮动按钮

whatsapp浮动按钮

whatsapp浮动按钮whatsapp.zip...

Navigate down the menu through jquery development

The core knowledge is to use jquery's hover method to achieve, The animation effe...

JQuery 两种方法解决刚创建的元素遍历不到的问题

刚创建的元素,使用jQuery的each方法来遍历,有时候会不起作用。原因不用多说,经常使用javascript的人应该都会知道,解决方案大致有2种:1、刚创建完元素的时候,就立刻使用each方法$(...

jquery如何获取div里面value的值以及原生写法

jquery写法$(this).attr("value")原生写法var value = document.getElementById(""+id+"...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。