Update index.html
Browse files- index.html +28 -5
index.html
CHANGED
|
@@ -116,7 +116,6 @@
|
|
| 116 |
'lite': 'https://open-avatar.holoworld.com.cn:8282/',
|
| 117 |
'lam': 'https://open-avatar.holoworld.com.cn:50032/'
|
| 118 |
};
|
| 119 |
-
|
| 120 |
function createIframe(type) {
|
| 121 |
const iframe = document.createElement('iframe');
|
| 122 |
iframe.setAttribute('allow', 'microphone; camera');
|
|
@@ -124,10 +123,35 @@
|
|
| 124 |
iframe.style.width = '100%';
|
| 125 |
iframe.style.height = '100%';
|
| 126 |
iframe.style.border = 'none';
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
return iframe;
|
| 129 |
}
|
| 130 |
-
|
| 131 |
function switchContent(type) {
|
| 132 |
// 移除所有active类
|
| 133 |
document.querySelectorAll('.split').forEach(el => {
|
|
@@ -141,14 +165,13 @@
|
|
| 141 |
const targetContainer = document.getElementById(type);
|
| 142 |
targetContainer.classList.add('active');
|
| 143 |
document.querySelector(`.title[onclick="switchContent('${type}')"]`).classList.add('active');
|
| 144 |
-
|
| 145 |
// 创建新的iframe
|
| 146 |
const iframeContainer = targetContainer.querySelector('.iframe-container');
|
| 147 |
iframeContainer.appendChild(createIframe(type));
|
| 148 |
}
|
| 149 |
-
|
| 150 |
// 初始化显示lite内容
|
| 151 |
switchContent('lite');
|
| 152 |
</script>
|
| 153 |
</body>
|
| 154 |
</html>
|
|
|
|
|
|
| 116 |
'lite': 'https://open-avatar.holoworld.com.cn:8282/',
|
| 117 |
'lam': 'https://open-avatar.holoworld.com.cn:50032/'
|
| 118 |
};
|
|
|
|
| 119 |
function createIframe(type) {
|
| 120 |
const iframe = document.createElement('iframe');
|
| 121 |
iframe.setAttribute('allow', 'microphone; camera');
|
|
|
|
| 123 |
iframe.style.width = '100%';
|
| 124 |
iframe.style.height = '100%';
|
| 125 |
iframe.style.border = 'none';
|
| 126 |
+
|
| 127 |
+
// 获取真正的来源域名
|
| 128 |
+
let trueOrigin = window.location.origin;
|
| 129 |
+
try {
|
| 130 |
+
// 如果页面是通过iframe嵌入的,获取顶级窗口的域名
|
| 131 |
+
if (window.parent !== window) {
|
| 132 |
+
trueOrigin = window.parent.location.origin;
|
| 133 |
+
}
|
| 134 |
+
} catch (e) {
|
| 135 |
+
// 跨域访问会抛出异常,此时使用当前域名
|
| 136 |
+
console.log('Cannot access parent origin due to cross-origin restrictions');
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
// 将来源信息作为URL参数传递给Gradio服务
|
| 140 |
+
const url = new URL(iframeSources[type]);
|
| 141 |
+
url.searchParams.set('referer_origin', trueOrigin);
|
| 142 |
+
url.searchParams.set('embed_timestamp', Date.now().toString());
|
| 143 |
+
|
| 144 |
+
// 在控制台打印调试信息
|
| 145 |
+
console.log('Embedding Gradio service:', {
|
| 146 |
+
type: type,
|
| 147 |
+
referer_origin: trueOrigin,
|
| 148 |
+
full_url: url.toString(),
|
| 149 |
+
is_embedded: window.parent !== window
|
| 150 |
+
});
|
| 151 |
+
|
| 152 |
+
iframe.src = url.toString();
|
| 153 |
return iframe;
|
| 154 |
}
|
|
|
|
| 155 |
function switchContent(type) {
|
| 156 |
// 移除所有active类
|
| 157 |
document.querySelectorAll('.split').forEach(el => {
|
|
|
|
| 165 |
const targetContainer = document.getElementById(type);
|
| 166 |
targetContainer.classList.add('active');
|
| 167 |
document.querySelector(`.title[onclick="switchContent('${type}')"]`).classList.add('active');
|
|
|
|
| 168 |
// 创建新的iframe
|
| 169 |
const iframeContainer = targetContainer.querySelector('.iframe-container');
|
| 170 |
iframeContainer.appendChild(createIframe(type));
|
| 171 |
}
|
|
|
|
| 172 |
// 初始化显示lite内容
|
| 173 |
switchContent('lite');
|
| 174 |
</script>
|
| 175 |
</body>
|
| 176 |
</html>
|
| 177 |
+
|