views:

29

answers:

2

is there anyway of loading a web page from a different domain into a jquery ui dialog?

A: 

Kind of hackish, but you could use a combination of YQL and JSONp

Jud Stephenson
any code example of this?
Niall Collins
http://james.padolsey.com/javascript/using-yql-with-jsonp/
Jud Stephenson
+4  A: 

Only if you're using an <iframe> or proxying the content through your own domain, otherwise you're blocked by the same-origin policy. For example:

$('<iframe src="http://www.google.com" />').dialog();
Nick Craver
@Niall - Like my example above, or an `<iframe>` wrapped in another element
Nick Craver
Ah.. this is clever. Bit of a hack but will achieve what is needed! Out of interest, what do you mean by "proxying the content through your own domain", how could i set this up?
Niall Collins
@Niall - Depends on your server platform, but you'd make a request to your domain, say `/proxy.php?url=http://www.google.com/` for example, and your server actually fetches the content and returns it...but the client only talks to your domain directly. Yahoo has some proxy class examples, just depends on which platform you're using.
Nick Craver
Ah yes, I understand what you mean now. I using .net/c# so could set up a http handler as my proxy. In your opinion which is the better approach - iframe or proxy? My concern with the proxy is that it means a server side hit.
Niall Collins
@Niall - It really depends what content you're loading, what are you sticking in the frame? If the user needs cookies for example, you'll want an `<iframe>` to make it seemless.
Nick Craver
The content will also contain a form with a postback action so thinking about it, iframe is probably my only option.
Niall Collins
Also if you're loading a page that doesn't know it's ending up in a dialog, it's going to expect to be it's own complete page anyway. An `<iframe>` is probably all you can do without major hackery.
Pointy