views:

26

answers:

1

Is there some way for me do something like the following in Javascript? ( Specifacly I want to do this from Javascript running in an Iphone OS UIWebView)

create a function called RedirectAndExecuteFunctionOnDomReady(url, function)

  1. Redirect to the HTML of the provided url
  2. When the new HTML DOM is ready, execute the provided function (which will modify the DOM)
  3. Finish loading/rendering the Page
A: 

No. Read up on the same origin policy (e.g. on Mozilla Developer Center or on Wikipedia).

However, the aside to your question about doing it in a UIWebView could open up some possibilities. I have no iPhone/Webkit/UIWebView experience, but does it support adding event handlers from your app itself? If so, you could add an event handler (not in JS, but in your iPhone app code) that gets triggered by the right domready event and adds the JS (again, from your app code) to the new document.

janmoesen
Okay then, is there a solution if I can live with the same origin restriction?Re: doing it from the App, I don't think it gives me enough control to break in exactly between the DOM Ready and the page rendering but it's a good start. Thanks.
Rube Vogel
@Rube: this is just a braindump, so forgive me for any errors. Your JavaScript function would disappear when going to another URL (and as such unloading the page and its JS). You would have to create an iframe to load your new URL and try to attach a handler for the domready event of that iframe's documentElement. I am not sure if the iframe loading blocks the script execution, though.
janmoesen