开发者

How to write live testing app for HTML and JS and capture page load events

I'm writing an in-browser Chrome app that will allow users to edit HTML and JS code and then be able to test their changes live.

My current method of doing this is to create a new window with JavaScript, create an IFrame in that window, and then inject the user's HTML or JS code into the IFrame. The problem with this though, is that the page load events of the IFrame can't be used by the script being live-tested. My app could manually call testWindow.iframe.contentWindow.onload, but that wouldn't work with the various events and methods used by the different JS libraries for their "domready"-style events.

Perhaps this is not possible, and I'll just have to send the code to the server a开发者_如何转开发nd have the server output it. I noticed apps like jsfiddle actually just ask what library and event you want.

Any ideas on how I can have live-testing in my app and still fire page loading events for the JS being tested?


You could use dispatchEvent on the iframe, which you know will be supported since you are making a Chrome app. Alternatively, for absolutely certain cross-browser compatibility (or some other reason) you could also send the script to your server (using Ajax) to be stored in a database, then linked to in the new window.


Just heard a lightening talk on http://vowsjs.org/ this evening. Haven't used it yet but I plan to explore this for testing web apps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜