当我点击链接时,它使用jquery打开两个新选项卡。这在firefox中有效,但在chrome和IE中不起作用。我的代码是:
<script>
$(document).ready(function() {
$("#clickme").on("click", function(event) {
event.preventDefault();
window.open("http://localadvertisingthatworks.com?lp_redirect_4779=http://marketing.localadvertisingthatworks.com/acton/attachment/6817/f-001f/1/-/-/-/-/A%20guide%20to%20Local%20Advertising.pdf&wp-cta-v=0&wpl_id=TbfyVCtDihutDKsQUF8xD62LGQTWMJ369hN&l_type=wpluid");
window.open("http://localadvertisingthatworks.com/download_thanks/");
});
});
</script>
<a class="inbound-button inbound-special-class" style="background-color: #2da8d2; border-color: #2da8d2; color: #fff; margin-right: 15px;" href="#" id="clickme" target="_blank"><i class="fa-download"></i>Download File</a>
由于chrome每次用户操作仅允许打开一个URL(第二次单击您的链接将打开第二个链接),因此您必须模拟打开操作(工作示例,仅允许弹出窗口,不知道为什么在chrome上需要这样做;不能使用SO Snippet,因为它阻止了新标签页的打开):
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<a class="inbound-button inbound-special-class" style="background-color: #2da8d2; border-color: #2da8d2; color: #fff; margin-right: 15px;" href="#" id="clickme" target="_blank"><i class="fa-download"></i>Download File</a>
<script type="text/javascript">
$(document).ready(function() {
$("#clickme").on("click", function(event) {
event.preventDefault();
// random ID that will not match any other link on page.
var id1 = 'mrl-by-jj-'+Math.floor(Math.random() * 1000);
var id2 = 'mrl-by-jj-'+Math.floor(Math.random() * 1000);
// create links
var a1 = $('<a/>', {
href: 'http://localadvertisingthatworks.com?lp_redirect_4779=http://marketing.localadvertisingthatworks.com/acton/attachment/6817/f-001f/1/-/-/-/-/A%20guide%20to%20Local%20Advertising.pdf&wp-cta-v=0&wpl_id=TbfyVCtDihutDKsQUF8xD62LGQTWMJ369hN&l_type=wpluid',
target: '_blank',
id: id1
});
var a2 = $('<a/>', {
href: 'http://localadvertisingthatworks.com/download_thanks/',
target: '_blank',
id: id2
});
// append to body
a1.appendTo('body');
a2.appendTo('body');
// trigger click and remove from DOM
$('#'+id1)[0].click();
$('#'+id2)[0].click();
$('#'+id1+', #'+id2).remove();
});
});
</script>
</body>
</html>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句