plugins - How can I make the "Preview Post" button save and preview in the same window?

admin2025-06-05  0

When you choose "Preview", which is actually a link,

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

the post is saved and the preview opens in a new window.

I'm sure there is a javascript event attached to this button, I'd like to override it so that it saves and then preview link opens in the same tab / window.

When you choose "Preview", which is actually a link,

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

the post is saved and the preview opens in a new window.

I'm sure there is a javascript event attached to this button, I'd like to override it so that it saves and then preview link opens in the same tab / window.

Share Improve this question edited Jan 1, 2019 at 11:42 Glorfindel 6113 gold badges10 silver badges18 bronze badges asked Dec 4, 2011 at 19:56 cwdcwd 1,8625 gold badges27 silver badges44 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 3

Here's a way to do it without modifying the core:

add_action('admin_footer','preview_same_window');

function preview_same_window(){ ?>
    <script type="text/javascript">

    jQuery(function($){

     jQuery('.preview.button').unbind().removeAttr('target');

            setTimeout(function(){
                jQuery('.preview.button').unbind().removeAttr('target');
            },250);

    });

    </script>
    <?php
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749054152a315963.html

最新回复(0)