![](/img/trans.png)
[英]Document Ready vs Window Onload - undefined is not a function
[英]$(window.document).ready(function () { … } not really ready?
我正在使用以下window.open(URL與當前頁面位於相同的主機/域):
function openWindow() {
var fswin = window.open(url, msg);
$(fswin.document).ready(function () {
setWindowTitle(fswin, msg) //set window title
});
}
有時我在嘗試將標題或fs_date值設置為以下值時出現null / undefined錯誤:
function setWindowTitle(fswin, fs_date) {
if ((fswin.document.title !== undefined) && (fswin.document.getElementById("fs_date") !== undefined))
{
fswin.document.title = fs_date;
fswin.document.getElementById("fs_date").value = fs_date;
}
else //if not loaded yet wait a 50ms then try again
{
setTimeout(setWindowTitle, 50); //wait 50ms and check again
}
}
這是間歇性錯誤,有時無法正常工作; 在我看來,我不能使用setTimeout(setWindowTitle,50),因為它不會將require參數傳遞給setWindow(fswin,fs_date)? 也許這就是問題,它有時會擊中setTimeout(...),因此不會傳遞fswin和fs_date嗎?
我在做什么錯,我該如何解決?
.ready()
方法並不關心綁定到什么元素,它總是在當前文檔上運行。
將load
事件用於其他元素。
$(fswin).on("load", function() {
setWindowTitle(fswin, msg);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.