mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-08 14:44:37 +00:00
Editor: do not reuse the preview tab when the user has navigated away.
See #32588. git-svn-id: https://develop.svn.wordpress.org/trunk@32809 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -4913,3 +4913,36 @@ function wp_delete_file( $file ) {
|
||||
@unlink( $delete );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a small JS snippet on preview tabs/windows to remove `window.name` on unload.
|
||||
* This prevents reusing the same tab for a preview when the user has navigated away.
|
||||
*
|
||||
* @since 4.3.0
|
||||
*/
|
||||
function wp_post_preview_js() {
|
||||
global $post;
|
||||
|
||||
if ( ! is_preview() || empty( $post ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Has to match the window name used in post_submit_meta_box()
|
||||
$name = 'wp-preview-' . (int) $post->ID;
|
||||
|
||||
?>
|
||||
<script>
|
||||
( function() {
|
||||
var query = document.location.search;
|
||||
|
||||
if ( query && query.indexOf( 'preview=true' ) !== -1 ) {
|
||||
window.name = '<?php echo $name; ?>';
|
||||
}
|
||||
|
||||
if ( window.addEventListener ) {
|
||||
window.addEventListener( 'unload', function() { window.name = ''; }, false );
|
||||
}
|
||||
}());
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user