目標:快速和骯髒的應用程序(僅客戶端)從一個頁面抓取一些參數並將結果放到一個新頁面上,該頁面可以打印然後關閉。然後可以更改原始頁面上的參數並彈出新頁面。以Javascript爲中心彈出窗口並傳遞html的正確方法
以此爲起點: https://developer.mozilla.org/en/DOM/window.open http://www.yourhtmlsource.com/javascript/popupwindows.html
概念驗證(最終版本將具有約10的輸入/參數)
HTML片段
<input type="text" id="x">
<form>
<input type=button value="Calculate" onClick="javascript:genResults()">
</form>
JS
function dirtypop(arg)
{
var popwin=window.open('','name','height=300,width=400,status=1,center=1');
popwin.document.write('<html><head><title>Square</title>');
popwin.document.write('</head><body>');
popwin.document.write('<h1>Squared plus one is: '+arg+'</h1>');
popwin.document.write('<p><a href="javascript:self.close()">Close</a> this window</p>');
popwin.document.write('</body></html>');
popwin.document.close();
};
function genResults()
{
x = document.getElementById('x').value;
if (x == parseFloat(x))
{
dirtypop(x*x+1);
}
};
這可以工作(在FF3.5和Chrome上測試),除非新窗口沒有彈出到中心。如何居中? Mozzila說需要chrome = yes並且談論UniversalPrivilege腳本,那些是什麼樣的野獸?
還有什麼可以改進的?
感謝您的回答,我的新年瑣事計劃取得了成功! :) – Sint 2010-01-05 07:40:50
由於實際上有幫助,請介意給我提高回答的答案?謝謝! – DoctorLouie 2010-01-05 21:22:17