0
你可以在窗口引用上使用JQuery嗎?我嘗試了以下,但沒有運氣。在窗口引用上使用JQuery?
function GetDiPSWindow() {
var DiPSURL = "/DiPS/index";
var DiPSWindow = window.open("", "DiPS", "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=520,height=875");
if (DiPSWindow.location.href === "about:blank") {
DiPSWindow.location = DiPSURL;
}
return DiPSWindow;
}
function AddRecipient(field, nameId) {
// Get window
var win = GetDiPSWindow();
// Attempt 1
$(win.document).ready(function() {
var input = win.document.getElementById(field + "_Input");
input.value = nameId;
});
// Attempt 2
$(win).ready(function() {
var input = win.document.getElementById(field + "_Input");
input.value = nameId;
});
// Attempt 3
$(win).load(function() {
var input = win.document.getElementById(field + "_Input");
input.value = nameId;
});
}
我在犯一個簡單的錯誤嗎?
編輯出於某種原因,win.document.readyState
是「完整的」。不知道這是否有所作爲。
我也曾嘗試:
視圖包含:
<script>var CallbackFunction = function() {}; // Placeholder</script>
的方法:
function AddRecipient(field, nameId) {
var DiPSURL = "/DiPS/index";
if (deliveryChannel === undefined) {
deliveryChannel = 0;
}
var DiPSWindow = GetDiPSWindow();
if (DiPSWindow.location.href === "about:blank") {
DiPSWindow.location = DiPSURL;
DiPSWindow.onload = function() { DiPSWindow.CallbackFunction = AddRecipient(field, nameId) }
} else {
var input = DiPSWindow.document.getElementById(field + "_Input");
input.value = input.value + nameId;
var event = new Event('change');
input.dispatchEvent(event);
}
}
不完全。內部jquery自動抓取本地'document',而不是你傳入的任何內容.ready。其他方法可能會工作。爲了完整的功能,我建議說窗口加載它自己的jQuery副本。 –
@KevinB說這是不可能的答案,我會接受它大聲笑 –