简体   繁体   English

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

[英]js function to open in new window or tab

I have a date picker php page and a button which goes to this 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;
}
}

This works, but opens in the same page which has a header footer etc, I need it to open in a new tab or window, how can I do this? 此方法有效,但在具有页眉页脚等的同一页面中打开,我需要在新标签页或窗口中打开它,该怎么办?

Have a look at something similar to the following: 看一看类似以下内容:

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;

Have a look here for further information: 在这里查看更多信息:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM