Comment #19 on issue 988 by [email protected]: Document.load is not supported
http://code.google.com/p/chromium/issues/detail?id=988
Yes, my workaround is based on the way posted by Gurreiro... in comment #9,
which is
using XMLHttpRequest.
I'd like resolve this problem in the Chrome client site instead of waiting
the change
of individual webkit. we can use user-script/extension to write our own
implementation of document.load method. The following is the sample code by
using th
way of user script. It works well on my machine. you also can download the
attachment, put it in "user data dir" > Default > "User Scripts", then run
your
chrome with "--enable-user-scripts"
if (!window.chromeCompatUtils)
window.chromeCompatUtils = { };
chromeCompatUtils.UserMethodObject = function(targetObject,
userMethodName,
userMethod) {
this.userMethodName_ = userMethodName;
// This target object in which the user method will be installed.
this.installTargetObject_ = targetObject;
this.userMethod_ = userMethod;
this.oldMethod_ = null;
}
chromeCompatUtils.UserMethodObject.prototype.install = function() {
this.oldMethod_ = this.installTargetObject_[this.userMethodName_];
this.installTargetObject_[this.userMethodName_] = this.userMethod_;
}
chromeCompatUtils.UserMethodObject.prototype.uninstall = function() {
this.installTargetObject_[this.userMethodName_] = this.oldMethod_;
}
var loadMethod = new chromeCompatUtils.UserMethodObject(
window.contentWindow.Document.prototype,
"load",
function(url) {
var xhr = new window.XMLHttpRequest();
var currentLoadDoc = this;
var internalOnLoad = function(){
if (xhr && xhr.responseXML) {
var xhrDoc = xhr.responseXML;
var clonedNode = xhrDoc.documentElement.cloneNode(true);
var rootElement = currentLoadDoc.documentElement ?
currentLoadDoc.documentElement : currentLoadDoc;
rootElement.appendChild(clonedNode, true);
currentLoadDoc.parseError = false;
} else {
currentLoadDoc.parseError = true;
}
xhr.removeEventListener("load", internalOnLoad, false);
xhr.removeEventListener("error", internalOnError, false);
// Call document.onload if it's existed.
if (currentLoadDoc.onload && typeof currentLoadDoc.onload == "function")
currentLoadDoc.onload();
};
var internalOnError = function() {
currentLoadDoc.parseError = true;
xhr.removeEventListener("load", internalOnLoad, false);
xhr.removeEventListener("error", internalOnError, false);
// Call document.onerror if it's existed.
if (currentLoadDoc.onerror && typeof currentLoadDoc.onload
== "function")
currentLoadDoc.onerror();
};
try {
this.async = !!this.async;
if (this.async) {
xhr.addEventListener("load", internalOnLoad, false);
xhr.addEventListener("error", internalOnError, false);
}
xhr.open("GET", url, this.async);
xhr.send(null);
// For synchronous call, directly call internalOnLoad.
if (!this.async)
internalOnLoad();
// Copy and append new dom tree into current document.
this.parseError = false;
} catch (e) {
this.parseError = true;
}
return !this.parseError;
});
loadMethod.install();
Attachments:
doc_load.user.js 2.8 KB
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--~--~---------~--~----~------------~-------~--~----~
Automated mail from issue updates at http://crbug.com/
Subscription options: http://groups.google.com/group/chromium-bugs
-~----------~----~----~----~------~----~------~--~---