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

admin5年前前端技术1118

自动触发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否则会被浏览器拦截


相关文章

webpack全局安装了,使用命令时却提示安装脚手架

全局安装了webpack ,使用webpack的时候,却有如下的提示One CLI for webpack must be installe...

H5页面移动端双击屏幕禁止页面放大

在meta标签中加入user-scalable=no属性...

Jquery中获取自定义标签data-id的值的几种常见方式

https://segmentfault.com/a/1190000005770912里面讲的很详尽了,在此就是总结一下做个笔记加深一下印象 。假如<div id="a&qu...

让TD 与div自动换行的css方法

word-wrap: break-word;  word-break: break-all; white-space: normal;...

Navigate down the menu through jquery development

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

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

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

发表评论    

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