[英]Best way to overwride all target=“_blank” to open links on same page
Is it possible to change all href links on a page to open on the same tab (target_self) instead of target blank.是否可以将页面上的所有 href 链接更改为在同一选项卡 (target_self) 上打开而不是目标空白。 Constraints: unable to access the code due to restrictions, and need a way to override all links to open in the same page, rather than on a new page.约束:由于限制无法访问代码,并且需要一种方法来覆盖所有链接以在同一页面中打开,而不是在新页面中打开。
Have tried the following试过以下
var otherWindow = window.open();
otherWindow.opener = null;
and和
$('a[target="_blank"]').each(function(){
$(this).removeAttr('target');
});
is there a way to target all links?有没有办法针对所有链接? or perhaps也许
You can try the below code.你可以试试下面的代码。 Try this https://jsfiddle.net/4wLq7k8x/1/试试这个https://jsfiddle.net/4wLq7k8x/1/
$('a[target="_blank"]').removeAttr('target');
$('a[target="_blank"]').removeAttr('target');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <a href="https://www.yahoo.com" target="_blank">Google</a> (target=_blank)<br> <a href="https://www.google.com" target="new">Yahoo</a> (target=new)
Below code is working for me.下面的代码对我有用。
Please try it.请尝试一下。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"
/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<body>
<a href="https://stackoverflow.com" target="_blank">Stack Overflow</a>
<a href="https://stackoverflow.com" target="_blank">Stack Overflow</a>
<a href="https://stackoverflow.com" target="_blank">Stack Overflow</a>
<script>
$(document).ready(function() {
$('a[target="_blank"]').prop("target", "_self");
});
</script>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.