0

我想url在新标签中打开一个。

我正在使用以下代码在新选项卡中打开 url。

var url = "/Billing/DownloadEDIForMultipleClaim?month=" + month + "&BillRequestIds=" + billRequestIds.join(',') + "&PatientIDs=" + patientIds.join(',');
window.open(url, '_blank'); //exception here

但这对我不起作用Uncaught TypeError: Cannot read property 'open' of undefined

我也使用了以下。

var url = "/Billing/DownloadEDIForMultipleClaim?month=" + month + "&BillRequestIds=" + billRequestIds.join(',') + "&PatientIDs=" + patientIds.join(',');
var win = window.open(url, '_blank');
if(win) {
    //Browser has allowed it to be opened
    win.focus();
} else {
    //Broswer has blocked it
    alert('Please allow popups for this site');
}

我已经看到了相关的问题。

如何使用 javascript 或 jquery 在新选项卡中打开 URL?

如何使用javascript在新标签中打开链接

但这对我不起作用。

4

1 回答 1

0

这可能有用: http: //jsfiddle.net/vraCM/12/ 似乎这个代码片段包含了你需要的东西。

$(function() {
   $("a[href^='http']:not([href*='jsfiddle.net'])").each(function() {
       $(this).click(function(event) {
             event.preventDefault();
             event.stopPropagation();
             window.open(this.href, '_blank');
        }).addClass('externalLink');
   });
});

js fiddle 包含的代码可以被操纵以适应您在警报或新窗口等中弹出窗口的参数。

此外,这篇文章可能值得一读。http://www.jqueryfaqs.com/Articles/Open-new-tab-in-browser-using-jQuery.aspx

于 2015-01-10T16:07:05.487 回答