Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8734119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:46:45+00:00 2026-06-13T09:46:45+00:00

I wrote a simple WordPress plugin the other day that saves a post and

  • 0

I wrote a simple WordPress plugin the other day that saves a post and shows a preview. Here is the javascript.

jQuery(document).ready(function($){

if (document.cookie.indexOf("previewCookie") >= 0){  
    //expires added for IE
    document.cookie="previewCookie=true; max-age=0;expires=0;path=/wp-admin/";          

    //quickPreviewOption is set in quick-preview.php  
    var previewURL = document.getElementById('post-preview');
    if(quickPreviewOption === 'current'){                                           
        window.location = previewURL;
    }
    if(quickPreviewOption === 'new'){
        window.open(previewURL,"wp_PostPreview","","true");
    }
}

$(document).keydown(function(e){
    if((e.ctrlKey || e.metaKey) && e.which == 83){

        //Find #save post if it's a draft. If post is published, #save-post doesn't exist.
        if($('#save-post').length){
            $('#save-post').click();    
        }
        else if($('#publish').length){
            $('#publish').click();
        }

        //Sets a cookie to open the preview on page refresh. Saving a post auotmatically refreshes the page.
        document.cookie = "previewCookie = true;max-age = 60;path=/wp-admin/";      
        return false;           
    }

}); 
});

This works when using the “html” editor in wordpress. However, using the “visual” editor in WordPress I can’t get any keydown function to fire. Not ctrl-s, ctrl-q etc. I don’t know what’s blocking it and I can’t find it in the source. I tried unbinding all keydown events and then rebinding only mine it didn’t unbind the WordPress keydown event. Anyone have any ideas?

Here’s the link to quick-preview plugin in case it helps. http://wordpress.org/extend/plugins/quick-preview/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:46:46+00:00Added an answer on June 13, 2026 at 9:46 am

    I’m posting a link to an answer that worked for me since no one else has answered this. Tiny MCE has it’s own keydown function which you have to hook into when WordPress initializes tinyMCE. The answer here worked for me. https://wordpress.stackexchange.com/questions/24113/hook-the-keydown-event-in-the-tinymce-post-editor

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple 2d strategy combat game that I wrote in javascript and
I wrote up a post in WordPress that included some code samples. I used
Here's my problem: I'm writing a WordPress plugin that helps budding CSS authors see
I am trying to write a simple Wordpress plugin, which updates a custom field
I wrote simple class that on the start it just increase the value of
I wrote a simple function, that makes emacs add matching quotes (so when I
I wrote a simple plugin which sets some css code using wp_options. It all
I wrote simple application that using the cell phone camera. When i trying to
I wrote simple benchmark that test performance of multyplying doubles vs BigDecimal. Is my
I wrote simple update/insert statements that are returning a syntax error, what am I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.