1

window.openポップアップ ウィンドウを開き、ウィンドウの内容全体を変更したいと考えています。

IE と Chrome では次のように動作しますが、firefoxでは動作しません

var Window= window.open("blanko.htm", "Win", "width=" + _iWidth + ",height=" + _iHeight + ",resizable=yes,left=" + iLeft + ",top=" + iTop + ",toolbar=1");
var Header = "<head><link rel='Stylesheet' href='CSS.css' type='text/css' /><style type='text/css'>td,th{font-size:11px;font-family:Arial;}body{font-family:Arial;font-size:12px;}</style></head>";
var Body = "<body><div>new Content</div></body>";

初挑戦:

 $(Window.document).ready(function () {
        $(Window.document.head).append(Header);
        $(Window.document.body).append(Body);
    });

2 回目の試行:

$(Window.document).ready(function () {
        $(Window.document).html(Header + Body);
});

この方法で試したことはすべて IE と Chrome で機能しますが、Firefox ではコンテンツが読み込まれ、1 秒後にwindow.openパラメーターで指定されたサイト (blanko.htm) に置き換えられます。

4

1 に答える 1

2

ここに純粋なJavascriptを使用すると、非常に簡単なソリューションになります。

var mynewWindow = window.open("", "Win", "width=" + _iWidth + ",height=" + _iHeight + ",resizable=yes,left=" + iLeft + ",top=" + iTop + ",toolbar=1");

        mynewWindow.document.write(
           '<html>' + 
             '<head>' + 
               '<title>' + myTitle + '</title>' + 
               '<link rel="Stylesheet" href="CSS.css" type="text/css" />' +
               //print on screen style
               '<style media="screen"> your CSS here </style>'+
               //Optional: print on printer style
               '<style media="print"> your CSS here </style>'+
             '</head>' + 
             '<body> <div>new Content</div> </body>' + 
           '</html>'
        );

役に立ったことを願っています

(これはすべての主要なインターネット ブラウザで動作するはずです)

于 2013-01-16T11:19:06.160 に答える