wpseek.com
A WordPress-centric search engine for devs and theme authors
wp_post_preview_js › WordPress Function
Since4.3.0
Deprecatedn/a
› wp_post_preview_js ( No parameters )
Defined at: |
|
Codex: |
Outputs a small JS snippet on preview tabs/windows to remove `window.name` when a user is navigating to another page.
This prevents reusing the same tab for a preview when the user has navigated away.Related Functions: post_preview, _show_post_preview, _set_preview, wp_is_post_revision, wp_get_post_revision
Source
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; ob_start(); ?> <script> ( function() { var query = document.location.search; if ( query && query.indexOf( 'preview=true' ) !== -1 ) { window.name = '<?php echo $name; ?>'; } if ( window.addEventListener ) { window.addEventListener( 'pagehide', function() { window.name = ''; } ); } }()); </script> <?php wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) ); }