我已经创建了一个简单的自定义谷歌地图,在标记上有链接。问题是所有的链接都有一个target="_blank"
,所以它们会在一个新的标签页上打开。我需要在同一窗口/选项卡上打开链接。我尝试了这段代码$('iframe a[target="_blank"]').removeAttr('target');
,但似乎Google API在页面加载后重新插入了target="_blank"
。有什么方法可以防止禁用该iframe的target="_blank"
吗?谢谢!
发布于 2020-02-06 06:26:54
您可以使用event.preventDefault()
自动停止浏览器的链接(从而打开一个新的选项卡),但我不确定这是否能很好地覆盖iframe中的事件
<a href="https://google.com" target="_blank">click me</a>
$('a').click(function(event) {
// stop the browser automatically opening a new tab
event.preventDefault();
// do whatever you want with the url
window.location = event.target.href
});
https://stackoverflow.com/questions/60084860
复制相似问题