呼び出されたときにウィンドウを開く関数を開発しましたが、返されますnull
。元の JavaScript 関数でウィンドウを開くと動作します。元の関数が制御を他の関数に渡すと思いますが、何らかの理由でこれが機能しません。
これが私の元の関数です。これは基本的に新しいJavaScriptファイルを呼び出してHTMLファイルをロードし、「準備ができたら」現在文字列の形式になっているHTMLファイルでwindow.openを表示する必要があります。
order.prototype.printMe = function() {
order_resume.loadthis("myTestPage.html", "showData");
// OPENING WINDOW HERE WORKS; but the the html file that is loaded
// in above line hasn't finsihed loading - so i need to show it form
// the function below once in "ready" state
/* child1 = window.open ("about:blank","_blank");
child1.document.write( myDocument );
child1.document.close();
*/
}
そして、元の関数から呼び出される私の関数は次のとおりです。
function showResume() {
this.req = false;
reservaResumen.prototype.showData = function() {
if (this.req.readyState == 4) {
child1 = window.open("about:blank", "_blank"); /// THIS RETURNS NULL
child1.document.write("test");
child1.document.close();
}
}
reservaResumen.prototype.loadthis = function(url, myMethod) {
if (window.XMLHttpRequest && !(window.ActiveXObject)) {
try {
this.req = new XMLHttpRequest();
}
catch (e) {
this.req = false;
}
}
else if (window.ActiveXObject) {
try {
this.req = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
this.req = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
this.req = false;
}
}
}
if (this.req) {
var loader = this;
this.req.onreadystatechange = function() {
eval("loader." + myMethod + ".call(loader)")
}
this.req.open("GET", url, true);
this.req.send("");
}
}