I requested How can I make the “Preview Post” button save and preview in the same window? around the Wordpress Stack Exchange, but this might be a much better question for Stack Overflow because it is more proportional to coding.

Wordpress includes a box that enables you to definitely save, preview, and publish your site posting:

Picture.png

The "Preview" button is really a hyperlink styled like a button:

<a tabindex="4" id="post-preview" target="wp-preview"
href="/?p=67&amp;preview=true" class="preview button">Preview</a>

My issue is which i can't appear to learn how to have that connect to open in the present window. Spot the target="wp-preview" part. I am attempting to eliminate that part, however i think there might be another function certain to that element because I truly can't have it to spread out in current tab / window, despite unbinding it and getting rid of the target attribute.

I am running the next code included in a wordpress plugin (you can observe more information regarding how to run this like a wordpress plugin below), but it's also easy to copy this into Chrome or Firefox's console to check this out yourself without modifying Wordpress. Please be aware that after testing you will need to use jQuery rather than $ in your functions as Wordpress uses the noconflict method, nevertheless the code below is working fine out of the box.

//select the node and cache the selection into a variable
var $node = jQuery('a.preview'); 

//add a 1px dotted outline to show we have the right element
$node.css('outline','1px dotted red'); 

//show current target
console.log($node.prop('target')); 
//show if anything is bound - nothing is for me ('undefined')
console.log($node.data('events')); 

//remove anything bound to it
$node.unbind(); 
//set target to _self (current window), just in case
$node.prop('target','_self'); 
//the remove the target attribute all together
$node.removeAttr('target'); 

//clone the node
var $clone = $node.clone(); 
//change the text to new
$clone.text('new'); 
//remove target from clone
$clone.removeAttr('target'); 
//unbind the clone
$clone.unbind(); 
//insert the clone after the original node
$node.after($clone); 

//show current target - now shows undefined for me
console.log($node.prop('target'));
//show if anything is bound - still 'undefined'
console.log($node.data('events'));

This is the way you'd work the code right into a theme or wordpress plugin:

// set up an action to set a function to run in the wp admin_footer
add_action('admin_footer','my_admin_footer_script',9999);

This is actually the function that contributes the javascript:

//this function can then be used to add javascript code to the footer

function my_admin_footer_script(){ ?>
    <script type="text/javascript">
    jQuery(function($){
     (above js code here)
    });
    </script>


    <?php
}

This is actually the result I finish track of. Basically click on the "test" link it'll open within the same window. Basically click on the Preview link still it opens inside a new tab.

Picture.png

ps: I am while using method from Things you may not know about jQuery to check on for bound occasions, and that i did not find anything bound, but Wordpress mainly uses jQuery and so i don't believe this is bound with another event handler.

You could attempt this:

jQuery('.preview.button').click(function(e){
    window.location.href = this.href;
    return false;
});

Works in the Chrome Inspector.