HTML 中的 <embed> 標籤缺少 allowFullScreen 屬性,需透過 jQuery 動態添加。
// 方法一:使用屬性選擇器(embed 無 id 時)
$("embed").attr("allowFullScreen", "true");
// 方法二:若有多個 embed,針對特定 src 或 index
$("embed[src*='player']").attr("allowFullScreen", "true");
// 或
$("embed").eq(0).attr("allowFullScreen", "true");
attr() 設定的是 **HTML 屬性**,對應 DOM 的 attributes 集合。allowFullScreen 為布林屬性,HTML5 標準寫法為 allowfullscreen(全小寫),現代瀏覽器兩者皆支援,建議統一小寫:.attr("allowfullscreen", "") 或 .prop("allowFullScreen", true)。<embed> 為替代元素,部分舊版瀏覽器需在父物件 <object> 上同步設定。<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<embed src="movie.swf" width="480" height="400" />
<script>
$(function() {
$("embed").prop("allowFullScreen", true); // 推薦用 prop 設定布林屬性
console.log($("embed").prop("allowFullScreen")); // true
});
</script>
</body>
</html>
使用 $("embed").prop("allowFullScreen", true) 或 .attr("allowfullscreen", "") 即可為 embed 標籤啟用全螢幕權限。