You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何为Outlook网页版(OWA)添加isread:no搜索功能的快捷按钮或快捷键?

OWA Unread Emails Shortcut: URL Parameter & jQuery Fixes

Hey there! I’ve dealt with similar OWA customization headaches before, so let’s break down two solid solutions for your unread emails shortcut—one super reliable, and another that fixes your jQuery key simulation issue.

1. The Most Reliable Method: URL Parameter Hack

OWA actually supports direct search via URL parameters, which avoids all the hassle of DOM manipulation or key simulation. Here’s how it works:

  • The search query isread:no can be appended to any OWA mail URL using the q parameter.
  • Example: If your current OWA inbox URL is https://outlook.office365.com/mail/inbox, just change it to https://outlook.office365.com/mail/inbox?q=isread:no and it’ll instantly load all unread emails.
  • For a universal shortcut that works no matter which folder you’re in, use https://outlook.office365.com/mail/search?q=isread:no—this takes you directly to the search results for unread messages.

For Chrome Extension Implementation

This is perfect for a Chrome extension button. Just add a browser action that modifies the current OWA tab’s URL:

chrome.action.onClicked.addListener((tab) => {
  if (tab.url.includes('outlook.office365.com/mail')) {
    const newUrl = tab.url.includes('?') 
      ? `${tab.url}&q=isread:no` 
      : `${tab.url}?q=isread:no`;
    chrome.tabs.update(tab.id, { url: newUrl });
  }
});

This method is way more stable than key simulation because it doesn’t rely on OWA’s constantly changing DOM structure.

2. Fixing Your jQuery Key Simulation Code

Your original code failed because it only triggered the Alt+Q event but didn’t wait for the search box to load, and jQuery’s event object might not have included all necessary properties. Here’s a revised version that works:

$('#unrbutton').click(function() {
  // Trigger Alt+Q to open the OWA search box
  const altQEvent = new KeyboardEvent('keydown', {
    key: 'q',
    altKey: true,
    bubbles: true,
    cancelable: true,
    keyCode: 81 // Fallback for older browsers
  });
  document.dispatchEvent(altQEvent);

  // Wait for the search box to render (adjust timeout if needed)
  setTimeout(() => {
    // Target OWA's search input (selector may vary slightly by OWA version)
    const searchInput = document.querySelector('input[aria-label="Search mail"]');
    if (searchInput) {
      // Clear existing text and input the unread query
      searchInput.value = 'isread:no';
      // Trigger input event so OWA detects the text change
      const inputEvent = new Event('input', { bubbles: true });
      searchInput.dispatchEvent(inputEvent);
      // Press Enter to execute the search
      const enterEvent = new KeyboardEvent('keydown', {
        key: 'Enter',
        bubbles: true,
        keyCode: 13
      });
      searchInput.dispatchEvent(enterEvent);
    }
  }, 150); // Short delay to let OWA load the search box
});

Key Fixes from Your Original Code:

  • Used native KeyboardEvent instead of jQuery’s $.Event for better browser compatibility.
  • Added a setTimeout to wait for OWA’s search box to appear after triggering Alt+Q.
  • Targeted the actual search input element instead of dispatching events to the entire document.
  • Triggered the input event to ensure OWA recognizes the text change before executing the search.

Note: OWA’s DOM selectors can change with updates, so you might need to adjust the input[aria-label="Search mail"] selector if this stops working. Use Chrome DevTools to inspect the search box and find the latest selector.


内容的提问来源于stack exchange,提问作者Brian Sargent

火山引擎 最新活动