如何创建JavaScript书签小工具,从当前页面生成Outlook日历事件?
快速创建Outlook日历事件的书签小工具
书签代码
压缩版(直接复制使用)
javascript:(function(){const t=document.title,e=window.location.href,n=window.getSelection().toString(),o=encodeURIComponent(`<h1>${t}</h1><div><a href="${e}">${t}</a></div><div>${n}</div>`),r=encodeURIComponent(t),i=encodeURIComponent(e);window.open(`https://outlook.live.com/calendar/0/deeplink/compose?subject=${r}&location=${i}&body=${o}`)})();
注释版(便于理解和自定义修改)
javascript:(function() { // 获取当前页面标题 const pageTitle = document.title; // 获取当前页面URL const pageUrl = window.location.href; // 获取用户选中的网页文本 const selectedText = window.getSelection().toString(); // 按需求构造描述的HTML内容 const description = `<h1>${pageTitle}</h1><div><a href="${pageUrl}">${pageTitle}</a></div><div>${selectedText}</div>`; // 对所有参数做URL编码,避免特殊字符导致格式错误 const encodedTitle = encodeURIComponent(pageTitle); const encodedLocation = encodeURIComponent(pageUrl); const encodedDescription = encodeURIComponent(description); // 打开Outlook网页版新建事件页面,自动填充预设字段 const outlookEventUrl = `https://outlook.live.com/calendar/0/deeplink/compose?subject=${encodedTitle}&location=${encodedLocation}&body=${encodedDescription}`; window.open(outlookEventUrl); })();
使用步骤
- 打开浏览器书签管理器(Chrome按
Ctrl+Shift+O,Firefox按Ctrl+Shift+B) - 点击「添加书签」,自定义书签名称(比如「添加到Outlook日历」)
- 将压缩版代码粘贴到书签的「URL」输入框,保存书签
- 浏览网页时,可先选中文本,点击该书签即可打开Outlook新建事件页面,所有预设字段已自动填充,你只需补充时间等信息即可
功能匹配说明
- 标题:自动填充当前网页的标题
- 位置:自动填充当前网页的URL
- 描述:生成包含网页标题、跳转链接、选中文本的HTML结构,方便后续查看时直接跳转回目标页面
内容的提问来源于stack exchange,提问作者Chet at C2IT
相关产品推荐
相关产品推荐

