Forum Moderators: open
var url = '/script_that_outputs_block_of_html.php?section='+current_section;
If you have something like that already, then you could just open an iframe to that same URL.
//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();
//Get the A tag
var id = $(this).attr('href');
//transition effect
$('#mask').fadeIn(500);
$('#mask').fadeTo("fast",0.6);
//transition effect
$(id).fadeIn(500);
});
//if close button is clicked
$('.window .close').click(function () {
$(this).hide();
$('#dialog').hide();
});
//if dialog is clicked
$('#dialog').click(function () {
$(this).hide();
$('.window').hide();
});
$("#dialog").load("/?page_id=18 #sub-content");
});
--HTML/PHP--
--Initial Modal Page--
<ul class="dropdown">
<li><a href="#dialog" name="modal">Case Studies</a></li>
<li><a href="#">Portfolio</a></li>
</ul>
...
<div id="dialog" class="window"> </div>
--Secondary Page--
<?php get_header(); ?>
<div id="sub-content">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<?php
if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
<div class="post">
<h2 id="post-<?php the_ID(); ?>"><?php the_title();?></h2>
<!-- close button is defined as close class -->
<a href="#" class="close">X Close</a>
<div class="entrytext">
<?php the_content('<p class="serif">Read the rest of this page »</p>'); ?>
</div>
</div>
<?php endwhile; endif; ?>
<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
</div>
</div>
<?php get_footer(); ?>
<li><a class="iframe" href="/?page_id=18?iframe">Case Studies</a></li>
If I target a div (#sub-content) I can see the targeted content in the initial iframe but then if I click on one of the links within the iframe, the page refreshes and bye-bye modal window.
<li><a class="iframe" href="/?page_id=18?iframe#sub-content">Case Studies</a></li>
If I leave the link as I pasted it above, the iframe opens the links within the window fine (but the entire page, not the targeted div, obv).
In jQuery 1.2 you can now specify a jQuery selector in the URL. Doing so will filter the incoming HTML document, only injecting the elements that match the selector.
$("#dialog").load("/?page_id=18 #sub-content");
Really interesting feature, but it completely changes the nature of advice I would give to you. :)
Typically, AJAX calls are passing a parameter to the script, and the script then only returns the relevant portion:
$("#dialog").load("/?page_id=18§ion=sub-content");
And, in that situation, your links returned from that script could easily point to:
/?page_id=18§ion=main-content
/?page_id=18§ion=sidebar
Or even point to other page_id's and, in an iframe, they would "just work." With that jQuery approach where the script itself has no idea how it's being used (or which portions will be used), you'd need to then *use* jQuery to dynamically rewrite the links to have different behaviors. And, skip the whole iframe approach.
I don't use jQuery, I just end up answering lots of questions about it. ;) So, in completely untested code:
$("#dialog").load("/?page_id=18 #sub-content", '', function(){ // callback after page is loaded
$("#dialog a").click( function(){ // attach an onclick event to all the new <a> elements
$("#dialog").load( $(this).href +" #sub-content"); // overwrite the default behavior
return false;
});
});