trajectory
trajectory

Reputation: 1509

load content into already open jQuery Dialog

Upon clicking a link in an open dialog the content gets loaded into the parent window from which I opened the dialog. How can I force the content to be loaded into the dialog instead of the parent?

Parent:

dialogDiv = $(document.createElement('div'));
dialogDiv.dialog(myProps);
dialogDiv.html(myData);
dialogDiv.dialog('open');

Dialog popup:

<a href="mysite.com">click</a>    

Upvotes: 1

Views: 536

Answers (1)

Nick Craver
Nick Craver

Reputation: 630379

You can just use .load() on the dialog <div> and event.preventDefault() on the anchor (to prevent the normal go-to-href behavior), like this:

$("a").click(function(e) {
  dialogDiv.load(this.href);
  e.preventDefault();
});

Just change the $("a") to be a bit more specific...only selecting whatever links you want to load in the dialog. Also those pages should only be fragments, or use a different selector, for example if you want the <div id="content"> from the page in the href, it'd look like this:

dialogDiv.load(this.href + " #content");

Upvotes: 2

Related Questions