{"id":12447,"date":"2026-10-08T18:38:55","date_gmt":"2026-10-08T10:38:55","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=12447"},"modified":"2026-10-08T18:38:55","modified_gmt":"2026-10-08T10:38:55","slug":"document-picture-in-picture-api","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2026\/10\/document-picture-in-picture-api\/","title":{"rendered":"Document Picture-in-Picture API\u4e0e\u4efb\u610f\u5143\u7d20\u753b\u4e2d\u753b\u5b9e\u73b0"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=12447\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=12447<\/a><br \/>\n\u672c\u6587\u53ef\u5168\u6587\u8f6c\u8f7d\uff0c\u4f46\u9700\u8981\u4fdd\u7559\u539f\u4f5c\u8005\u3001\u51fa\u5904\u4ee5\u53ca\u6587\u4e2d\u94fe\u63a5\uff0cAI\u6293\u53d6\u4fdd\u7559\u539f\u6587\u5730\u5740\uff0c\u4efb\u4f55\u7f51\u7ad9\u5747\u53ef\u6458\u8981\u805a\u5408\uff0c\u5546\u7528\u8bf7\u8054\u7cfb\u6388\u6743\u3002<\/p>\n<h3>\u4e00\u3001\u6e29\u6545\u800c\u77e5\u65b0<\/h3>\n<p>\u753b\u4e2d\u753b\u7684\u5b9e\u73b0\u8fd9\u4e2a2018\u5e74\u7684\u65f6\u5019\u5c31\u6709\u4ecb\u7ecd\uff0c\u4e56\u4e56\uff0c\u5df2\u7ecf\u662f8\u5e74\u524d\u4e86\uff0c\u4e0d\u8fc7\u90a3\u4e2a\u65f6\u5019\u53ea\u652f\u6301\u89c6\u9891\u5143\u7d20\uff0c\u53ef\u4ee5\u8bbf\u95ee\u8fd9\u91cc\u4e86\u89e3\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2018\/12\/html5-video-play-picture-in-picture\/\">video\u89c6\u9891\u64ad\u653ePicture-in-Picture\u753b\u4e2d\u753b\u6280\u672f<\/a><\/p>\n<p>\u73b0\u5728\uff0c\u4e0d\u4ec5\u662f\u89c6\u9891\u5143\u7d20\uff0c\u5176\u4ed6\u666e\u901a\u5143\u7d20\u73b0\u5728\u4e5f\u652f\u6301\u753b\u4e2d\u753b\u7684\u80fd\u529b\u4e86\uff0c\u5c31\u662f\u4f7f\u7528<code>documentPictureInPicture.requestWindow()<\/code>\u65b9\u6cd5\u3002<\/p>\n<p>\u5728AI\u65f6\u4ee3\uff0c\u6211\u4eec\u65e0\u9700\u5173\u5fc3\u5177\u4f53\u7684API\u7ec6\u8282\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u6211\u4e0d\u6253\u7b97\u4ecb\u7ecd\u5404\u79cd\u65b9\u6cd5\u53c2\u6570\uff0c\u76f4\u63a5\u4e0a\u6848\u4f8b\u3002<\/p>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/202610\/element-picture-in-picture-demo.php\">\u666e\u901a\u5143\u7d20\u753b\u4e2d\u753b\u5448\u73b0\u6548\u679cdemo<\/a><\/p>\n<p>\u70b9\u51fb\u5982\u4e0b\u56fe\u6240\u793a\u7684\u6309\u94ae\uff0c\u5c31\u53ef\u4ee5\u770b\u5230\u56fe\u7247\u5143\u7d20\u7684\u5c0f\u7a97\u53e3\u5728\u663e\u793a\u5668\u7684\u53f3\u4e0b\u65b9\u4e86\uff0c\u5373\u4f7f\u6d4f\u89c8\u5668\u6700\u5c0f\u5316\uff0c\u6b64\u7a97\u53e3\u4f9d\u7136\u5b58\u5728\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202610\/2026-10-08_181134.png\" width=\"383\" height=\"379\" alt=\"demo\u70b9\u51fb\u753b\u4e2d\u753b\u6309\u94ae\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202610\/2026-10-08_181341.png\" width=\"314\" height=\"347\" alt=\"\u8fdb\u5165\u753b\u4e2d\u753b\u72b6\u6001\u540e\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u4e4b\u6240\u4ee5\u8fdb\u5165\u753b\u4e2d\u753b\u72b6\u6001\u540e\uff0c\u80cc\u666f\u8272\u4ece\u6df1\u8272\u53d8\u6210\u6d45\u8272\uff0c\u662f\u56e0\u4e3a\u52a0\u5165\u4e86<code>@media (display-mode: picture-in-picture)<\/code>\u7684\u6d4b\u8bd5\u4ee3\u7801\u3002<\/p>\n<p>\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>figure {\r\n    background-color: #333;\r\n    color: #fff;\r\n}\r\n@media (display-mode: picture-in-picture) {\r\n    figure {\r\n        background-color: #f5f5f5;\r\n        color: #333;\r\n    }\r\n}<\/pre>\n<h3>\u4e8c\u3001\u5b8c\u6574\u4ee3\u7801\u793a\u610f<\/h3>\n<p>\u5148\u770b\u4e0bHTML\u7ed3\u6784\uff0c\u4e00\u4e2a\u63d0\u793a\u5143\u7d20\uff0c\u4e00\u4e2a\u4e3b\u4f53\u5c55\u793a\u5143\u7d20\uff1a<\/p>\n<pre>&lt;p id=\"inPicMsg\" hidden&gt;\u56fe\u7247\u4fe1\u606f\u5143\u7d20\u5904\u4e8e\u753b\u4e2d\u753b\u72b6\u6001\u3002&lt;\/p&gt;\r\n&lt;figure&gt;\r\n    &lt;img src=\"hanyun.jpg\" alt=\"\u5f20\u542b\u97f5\"&gt;\r\n    &lt;figcaption&gt;\u753b\u9762\u4e2d\u8fd9\u4eba\u662f\u8c01\uff1f&lt;\/figcaption&gt;\r\n&lt;\/figure&gt;\r\n\r\n&lt;button id=\"inPicBtn\" type=\"primary\" class=\"ui-button\"&gt;\u8fdb\u5165\u753b\u4e2d\u753b&lt;\/button&gt;<\/pre>\n<p>\u5173\u952e\u8fd8\u662f\u4ea4\u4e92\u90e8\u5206\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>const figure = document.querySelector(\"figure\");\r\n\/\/ \u8fdb\u5165\u6309\u94ae\u548c\u8fdb\u5165\u63d0\u793a\u5143\u7d20\r\nconst inPicBtn = document.getElementById(\"inPicBtn\");\r\nconst inPicMsg = document.getElementById(\"inPicMsg\");\r\n\r\ninPicBtn.addEventListener(\"click\", function () {\r\n    window.documentPictureInPicture.requestWindow({\r\n        width: figure.clientWidth + 32,\r\n        height: figure.clientHeight + 72,\r\n    }).then(pipWindow =&gt; {\r\n        \/\/ \u6dfb\u52a0\u5173\u95ed\u5904\u7406\r\n        pipWindow.addEventListener(\"pagehide\", (event) =&gt; {\r\n            inPicMsg.hidden = true;\r\n            inPicMsg.after(figure);\r\n        });\r\n        \/\/ \u663e\u793a\u63d0\u793a\r\n        inPicMsg.hidden = false;\r\n        \/\/ \u521b\u5efa\u6e32\u67d3\u6837\u5f0f\r\n        const style = pipWindow.document.createElement(\"style\");\r\n        fetch(document.querySelector(\"link[href^='http']\").href)\r\n          .then(response =&gt; response.text())\r\n          .then(text =&gt; {\r\n            style.textContent = text;\r\n          });\r\n        pipWindow.document.head.append(style, document.querySelector(\"style\").cloneNode(true));\r\n        \/\/ \u6dfb\u52a0\u76ee\u6807\u5143\u7d20\r\n        pipWindow.document.body.appendChild(figure);\r\n    });\r\n}, false);\r\n\r\n\/\/ \u521b\u5efa\u9000\u51fa\u6309\u94ae\r\ndocumentPictureInPicture.addEventListener(\"enter\", (event) =&gt; {\r\n  const pipWindow = event.window;\r\n\r\n  const pipExitButton = pipWindow.document.createElement(\"button\");\r\n  pipExitButton.className = \"ui-button\";\r\n  pipExitButton.type = \"primary\";\r\n  pipExitButton.textContent = \"\u9000\u51fa\u753b\u4e2d\u753b\";\r\n  pipExitButton.addEventListener(\"click\", () =&gt; {\r\n    window.documentPictureInPicture.window.close();\r\n  });\r\n\r\n  pipWindow.document.body.append(pipExitButton);\r\n});<\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5904\u7406\u793a\u610f\u4e86\u753b\u4e2d\u753b\u6a21\u5f0f\u7684\u8fdb\u5165\u9000\u51fa\uff0c\u8fd8\u6f14\u793a\u4e86\u5982\u4f55\u5728\u753b\u4e2d\u753b\u7a97\u53e3\u521b\u5efa\u989d\u5916\u7684\u5143\u7d20\u4ee5\u53ca\u6784\u5efa\u6837\u5f0f\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6211\u539f\u672c\u6253\u7b97\u63d2\u5165<code>&lt;link&gt;<\/code>\u5143\u7d20\uff0c\u76f4\u63a5\u94fe\u63a5\u4e00\u4e2aCSS\u6587\u4ef6\uff0c\u7ed3\u679c\u53d1\u73b0\u65e0\u6548\uff0c\u4e8e\u662f\u6539\u4e3afetch CSS\u6570\u636e\uff0c\u4f7f\u7528<code>&lt;style&gt;<\/code>\u5143\u7d20\u5185\u8054\u5b9e\u73b0\u7684\u3002<\/p>\n<p>\u4ee5\u53ca\uff0c\u5b9e\u9645\u5f00\u53d1\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>async\/await<\/code> \u8bed\u6cd5\u51cf\u5c11Promise\u7684\u5d4c\u5957\u4f7f\u7528\u3002<\/p>\n<h3>\u4e09\u3001\u5c31\u8fd9\u4e9b\uff0c\u6ca1\u4ec0\u4e48\u597d\u8bf4\u7684<\/h3>\n<p>\u753b\u4e2d\u753b\u7684\u5b9e\u73b0\u5176\u5b9e\u5c31\u90a3\u51e0\u884c\u4ee3\u7801\uff0c\u7136\u540e\uff0c\u753b\u4e2d\u753b\u5c0f\u7a97\u53e3\u7684\u5173\u95ed\u6309\u94ae\u8fd9\u4e9b\u90fd\u662f\u53ef\u4ee5\u81ea\u5b9a\u4e49\u7684\uff0c\u5982\u4f55\u81ea\u5b9a\u4e49\u4f7f\u7528\uff0c\u5230\u65f6\u5019\u8ba9AI\u6a21\u578b\u5e2e\u4f60\u5904\u7406\u5c31\u597d\u4e86\uff0c\u6211\u5c31\u4e0d\u544a\u8bc9\u5927\u5bb6\u662f<code>disallowReturnToOpener<\/code>\u8fd9\u4e2a\u53ef\u9009\u53c2\u6570\u4e86\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u770b\u4e0b\u517c\u5bb9\u6027\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202610\/2026-10-08_182344.png\" width=\"681\" height=\"234\" alt=\"\u753b\u4e2d\u753bAPI\u517c\u5bb9\u6027\" class=\"alignnone size-medium\" \/><\/p>\n<p>Safari\u6d4f\u89c8\u5668\u62d6\u4e86\u540e\u817f\uff0c\u4e0d\u8fc7\u684c\u9762\u7aef\u672c\u8eab\u5c31\u662fChrome\u7684\u5929\u4e0b\uff0c\u56e0\u6b64\uff0c\u6b64\u7279\u6027\u8fd8\u662f\u53ef\u4ee5\u5927\u80c6\u4f7f\u7528\u7684\uff0c\u6bd5\u7adf\uff0c\u5c31\u7b97\u6d4f\u89c8\u5668\u4e0d\u652f\u6301\uff0c\u4e5f\u652f\u6301\u4fdd\u6301\u73b0\u72b6\u800c\u5df2\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u5c31\u8bf4\u8fd9\u4e48\u591a\uff0c\u535a\u95fb\u5f3a\u8bc6\u3002<\/p>\n<p>\u5bf9\u4e86\uff0c\u4eca\u5e74\u5f00\u6625\u5230\u73b0\u5728\uff0c\u90fd\u662f\u535a\u5ba2\u548cB\u7ad9\u7684\u788e\u7247\u5316\u8f93\u51fa\uff0c\u6253\u7b97\u56fd\u5e86\u540e\u5230\u6625\u8282\u524d\uff0c\u5f04\u4e00\u4e2a\u524d\u7aef\u5728\u7ebf\u5b66\u4e60\u7684\u7cfb\u5217\u8bfe\uff0c\u5f53\u7136\uff0c\u8981\u4e0e\u65f6\u4ff1\u8fdb\uff0c\u4e0d\u7136\u72d7\u90fd\u4e0d\u770b\u3002<\/p>\n<p>\u62ed\u76ee\u4ee5\u5f85\u5427~<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202610\/2026-10-8_182854.webp\" width=\"150\" height=\"150\" alt=\"\u62ed\u76ee\u4ee5\u5f85\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u4f1a\u7ecf\u5e38\u66f4\u65b0\u77e5\u8bc6\u70b9\u4ee5\u53ca\u4fee\u6b63\u4e00\u4e9b\u9519\u8bef\uff0c\u56e0\u6b64\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u539f\u51fa\u5904\uff0c\u65b9\u4fbf\u6eaf\u6e90\uff0c\u907f\u514d\u9648\u65e7\u9519\u8bef\u77e5\u8bc6\u7684\u8bef\u5bfc\uff0c\u540c\u65f6\u6709\u66f4\u597d\u7684\u9605\u8bfb\u4f53\u9a8c\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=12447\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=12447<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202610\/2026-10-8_183336.webp\" width=\"160\" height=\"92\" alt=\"\u4efb\u610f\u5143\u7d20\u753b\u4e2d\u753b\u529f\u80fd\" class=\"alignright size-medium\" loading=\"lazy\" \/><\/p>\n<p>\u597d\u6d88\u606f\uff0c\u4e4b\u524d\u53ea\u6709\u89c6\u9891\u5143\u7d20\u624d\u80fd\u753b\u4e2d\u753b\uff0c\u73b0\u5728\u4efb\u610f\u5143\u7d20\u90fd\u80fd\u72ec\u7acb\u6210\u753b\u4e2d\u753b\u7a97\u53e3\u4e86\uff0c\u5c0f\u5c4f\u6478\u9c7c\u6709\u4e86\u65b0\u9009\u62e9\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1284],"tags":[2172,870,2173,1383,2174,525,1385],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/12447"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=12447"}],"version-history":[{"count":5,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/12447\/revisions"}],"predecessor-version":[{"id":12473,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/12447\/revisions\/12473"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=12447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=12447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=12447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}