I want one of the page adding editors on site to have a preview buttons associated with it. When user clicks preview the content gets saved and if the save is successful a page preview window is launched. The problem here is that the preview windows is blocked by browser's pop-up blocker. What can I make to "fool" the browser ?
I was thinking of maybe using fancybox with an iframe for the preview page, but wouldn't that be confusing for the user ? Is this a workaround for my problem ?
$('body').delegate('#preview_<?=$id?>', 'click', function() {
$.post( 'somefile.php',
{user : '<?=$user?>', type:'page', id: <?=$id?>, title : $('input[name=title]').val(), post_content: $('#editor').val()},
function(data)
{
if(data.indexOf('succesfully') != -1){
window.open("http://example.com/preview_page.php?id=<?=$id?>");
return false;
}
}
);
});
Here's the html of the form.
<form id="addPage" method="post" action="somefile.php">
<label for="title" class="grid_4">Title</label>
<input type="text" class="grid_12" name="title" value="<?=$page['title']?>" />
<label for="post_content" class="grid_16">Content</label>
<textarea class="grid_11" name="post_content" id="editor"><?=$page['content']?></textarea>
<input type="hidden" name="user" value="<?=$_SESSION['user']?>" />
<input type="hidden" name="id" value="<?=$id?>" />
<input type="hidden" name="type" value="page" />
<input type="button" value="Preview" name="preview" id="preview_<?=$id?>" />
<input type="submit" value="Submit" name="submit" />
</form>