所以我想在JS和HTML使一个按钮或者一个在默认浏览标签打开新的标签页Androind和它不工作
这是我的 html 和 js 代码:
HTML
<button class="btn btn-success a-new-tab" data-href="{{ $url }}">My btn</button>
JS
$(document).ready(function () {
$('.a-new-tab').on('click', function (event) {
event.preventDefault();
window.open($(this).attr('data-href'), '_blank');
window.focus();
})
});
请帮我!
我在 iPhone/iPad Safari 浏览器上遇到了同样的问题,所以下面的解决方案对我有用。也许,它也可以帮助你。
HTML
<button class="a-new-tab" data-href="https://www.google.com/">My btn</button>
在button
点击,我发现了data-href
,然后设置onclick
属性相同的按钮,并在属性中打开一个新窗口
$(".a-new-tab").on("click", function () {
var url = $(this).attr("data-href");
$(this).attr( "onclick", "window.open('" + url + "'); return false;" );
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句