if (!shouldShowCloseBar) { iframe.style.height = ''; // 清除内联样式,使用CSS类 iframe.classList.add('btm-nav-with-menu'); contentEl.style.height = '100%'; } else { iframe.style.height = ''; // 清除内联样式,使用CSS类 iframe.classList.add('btm-nav-with-menu'); contentEl.style.height = 'calc(100% - 35px)'; } } else { if (menuBar) menuBar.style.display = 'none'; // 完全占满屏幕,但在移动端考虑安全区域 iframe.style.top = '0'; iframe.classList.remove('btm-nav-with-menu'); // 移除菜单栏类 iframe.classList.add('btm-nav-fullscreen'); // 添加全屏类用于CSS安全区域适配 if (isMobileDevice()) { // 移动端:让CSS的env()处理安全区域,JavaScript只设置基本样式 iframe.style.bottom = '0'; iframe.style.left = '0'; iframe.style.right = '0'; iframe.style.width = '100%'; iframe.style.maxWidth = 'none'; iframe.style.height = '100vh'; iframe.style.transform = 'none'; } else { // 桌面端:保持居中显示 iframe.style.bottom = '0'; iframe.style.left = '50%'; iframe.style.right = 'auto'; iframe.style.width = '100%'; iframe.style.maxWidth = '760px'; iframe.style.height = '100vh'; iframe.style.transform = 'translateX(-50%)'; } if (!shouldShowCloseBar) { contentEl.style.height = '100%'; // iframe内容占满 } else { contentEl.style.height = 'calc(100% - 35px)'; // 减去关闭栏高度 } } iframe.style.display = 'block'; // 显示加载动画 var loadingEl = document.getElementById('btmNavLoading'); var loadingTip = document.getElementById('btmNavLoadingTip'); if (loadingEl) { loadingEl.style.display = 'flex'; // 根据是否显示关闭栏来设置提示内容 if (loadingTip) { loadingTip.className = 'btm-nav-loading-tip'; if (shouldShowCloseBar) { loadingTip.classList.add('show-with-bar'); } else { loadingTip.classList.add('show-no-bar'); } } } // 添加iframe加载完成事件 contentEl.onload = function() { // 隐藏加载动画 if (loadingEl) { loadingEl.style.display = 'none'; } try { // 尝试访问iframe内容(只对同域有效) var iframeDoc = contentEl.contentDocument || contentEl.contentWindow.document; if (iframeDoc && iframeDoc.body) { // 恢复iframe内页面的原始样式 var iframeBody = iframeDoc.body; iframeBody.style.maxWidth = ''; iframeBody.style.margin = ''; iframeBody.style.position = ''; // 确保iframe内的元素保持原有样式 var elements = iframeDoc.querySelectorAll('*'); for (var i = 0; i < elements.length; i++) { elements[i].style.maxWidth = ''; } } } catch (e) { // 跨域iframe无法访问内容,这是正常的安全限制 // 对于跨域iframe,我们无法直接修改其内部样式 } }; }, 100); } } // 判断是否应该显示关闭栏 function getShouldShowCloseBar(menuItem) { // 如果全局关闭栏功能被禁用,直接返回false if (!globalSettings.closeBar.enabled) { return false; } // 如果菜单项有单独配置,使用菜单项配置 if (menuItem && typeof menuItem.showCloseBar !== 'undefined') { return menuItem.showCloseBar; } // 否则使用全局默认设置 return globalSettings.closeBar.defaultShow; } // 判断是否应该显示菜单栏 function getShouldShowMenuBar(menuItem) { // 如果全局菜单栏功能被禁用,直接返回false if (!globalSettings.menuBar.enabled) { return false; } // 如果菜单项有单独配置,使用菜单项配置 if (menuItem && typeof menuItem.showMenuBar !== 'undefined') { return menuItem.showMenuBar; } // 否则使用全局默认设置 return globalSettings.menuBar.defaultShow; } // 切换更多菜单显示/隐藏 function toggleMoreMenu() { var moreMenu = document.getElementById('btmNavMoreMenu'); if (moreMenu) { if (moreMenu.style.display === 'block') { moreMenu.style.display = 'none'; } else { moreMenu.style.display = 'block'; } } } // 刷新当前iframe页面 function refreshIframe() { var contentEl = document.getElementById('btmNavIframeContent'); var loadingEl = document.getElementById('btmNavLoading'); var loadingTip = document.getElementById('btmNavLoadingTip'); if (contentEl && contentEl.src) { // 显示加载动画 if (loadingEl) { loadingEl.style.display = 'flex'; // 刷新时总是显示有关闭栏的提示(因为刷新是从更多菜单触发的) if (loadingTip) { loadingTip.className = 'btm-nav-loading-tip show-with-bar'; } } // 重新加载页面 contentEl.src = contentEl.src; } toggleMoreMenu(); // 关闭菜单 } // 分享当前页面 function shareCurrentPage() { var contentEl = document.getElementById('btmNavIframeContent'); if (contentEl && contentEl.src) { if (navigator.share) { navigator.share({ title: document.getElementById('btmNavIframeTitle').textContent, url: contentEl.src }); } else { // 备用方案:复制到剪贴板 copyCurrentUrl(); } } toggleMoreMenu(); } // 复制当前页面链接 function copyCurrentUrl() { var contentEl = document.getElementById('btmNavIframeContent'); if (contentEl && contentEl.src) { if (navigator.clipboard) { navigator.clipboard.writeText(contentEl.src).then(function() { alert('链接已复制到剪贴板'); }); } else { // 备用方案 prompt('复制此链接:', contentEl.src); } } toggleMoreMenu(); } // 在新窗口打开当前页面 function openInNewWindow() { var