js函数在新窗口或选项卡中打开

时间:2017-04-15 13:32:25

标签: javascript function

我有一个日期选择器php页面和一个转到此功能的按钮

function clickme()
{
if (checkEmpty("date")) return;
if (checkEmpty("end")) return;

var d = convertDate(EL("date").value);
var e = convertDate(EL("end").value);
if (d == null) {
    EL("date").focus();
alert("The date must be in dd/mm/yyyy format.");
return;
}
if (e == null) {
    EL("end").focus();
alert("The date must be in dd/mm/yyyy format.");
return;
}

var x = getXmlHttpRequest();
if (x == null) {
    alert("Unable to get XmlHttpRequest");
    return;
}

var u = "dates-xl.php?date="+ d +"&end=" + e;

x.open("GET", u, false);
x.send();

var t = x.responseText;
if (t != null && t != "") {
    var e = EL("content");
    e.innerHTML = t;
}
}

这样可行,但是在同一个页面中打开,它有一个页眉页脚等,我需要它在新标签页或窗口中打开,我该怎么做?

1 个答案:

答案 0 :(得分:0)

看看类似于以下的内容:

var u = "dates-xl.php?date="+ d +"&end=" + e;

x.open("GET", u, false);
x.send();

var t = x.responseText;

var win = window.open("", "_blank"); // This will only work if this being called as a result of a user action (e.g. a button click).
win.document.body.innerHTML = t;

请点击此处了解更多信息:

https://stackoverflow.com/a/19078591/3713362

https://www.w3schools.com/jsref/met_win_open.asp