XDomainRequest
is Internet Explorer 8’s cross-domain request function. It would be easy to add support for it in Firefox 3.5 using native cross-domain XMLHttpRequest
s, but that wouldn’t work in Firefox 3, Opera 9.6-10, and Safari 4. I have created a library named XXDomainRequest (means “Cross-browser XDomainRequest”) that builds on the pmxdr client library to create a fully API compatible version of XDomainRequest. Go to the XXDomainRequest project page to see (and run) the examples that request resources on code.eligrey.com.
Eli Grey
Reusable pmxdr instances
I just released version 0.0.4 of the pmxdr client code to support reusable instances where the same iframe can be used for mutiple pmxdr requests to a domain. It’s still the same interface, but you need to call pmxdr.request()
instead of pmxdr()
to do a normal request. Instances are created with new pmxdr(host)
where host is any URI from the website you want to request (pmxdr figures out where the API is located automatically). Then just call the request
method on the instance once the interface iframe has loaded, which you can find out when instance calls it’s onload
method once it’s loaded if you set it. The request method now also accepts an array of requests. To start loading the instance, you call it’s init
method. To remove the interface frame, you call it’s unload
method. Another thing added is the ability to completely remove pmxdr using its destruct
method, which removes all event listeners and deletes the pmxdr variable. This does not delete any still-existing interface frames so don’t forget to unload
them when you are done to avoid memory leaks.
Using reusable instances saves much more overhead than repeatedly re-requesting a website’s pmxdr host api. When I updated the demo to use a single instance for requesting eligrey.com, it started finishing a multitude of times faster. This is an example of using a reusable instance that uses one interface to make three requests:
var exampleDotCom = new pmxdr("http://example.com"); exampleDotCom.onload = function() { this.request([ { uri : "/foo.html", callback: responseHandlers.foo },{ uri : "/bar.html", callback: responseHandlers.bar },{ uri : "/baz.html", callback: responseHandlers.baz } ]); }; exampleDotCom.init() // after all responseHandlers[x] are called, call exampleDotCom.unload() |