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
2010-10-07 21:25:15
any code example of this?
Niall Collins
2010-10-07 21:27:19
http://james.padolsey.com/javascript/using-yql-with-jsonp/
Jud Stephenson
2010-10-07 21:29:09
+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
2010-10-07 21:25:54
@Niall - Like my example above, or an `<iframe>` wrapped in another element
Nick Craver
2010-10-07 21:34:04
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
2010-10-07 21:35:07
@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
2010-10-07 21:38:00
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
2010-10-07 21:41:27
@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
2010-10-07 21:42:26
The content will also contain a form with a postback action so thinking about it, iframe is probably my only option.
Niall Collins
2010-10-07 21:47:24
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
2010-10-07 23:32:18