|
@@ -105,54 +105,56 @@ const handleIframeLoad = async (event: Event) => {
|
|
|
try {
|
|
|
// 等待iframe完全加载
|
|
|
await nextTick()
|
|
|
-
|
|
|
- // 检查iframe是否可访问(同源检查)
|
|
|
- if (iframe.contentWindow && iframe.contentDocument) {
|
|
|
- const iframeDoc = iframe.contentDocument
|
|
|
- const iframeHead = iframeDoc.head || iframeDoc.getElementsByTagName('head')[0]
|
|
|
+ setTimeout(() => {
|
|
|
+ // 检查iframe是否可访问(同源检查)
|
|
|
+ if (iframe.contentWindow && iframe.contentDocument) {
|
|
|
+ const iframeDoc = iframe.contentDocument
|
|
|
+ const iframeHead = iframeDoc.head || iframeDoc.getElementsByTagName('head')[0]
|
|
|
|
|
|
- if (iframeHead) {
|
|
|
+ if (iframeHead) {
|
|
|
// 动态导入JS文件
|
|
|
- const [awsJs, jqJs, jieTuJs] = await Promise.all([
|
|
|
- import('./aws-sdk-2.235.1.min.js'),
|
|
|
- import('./jquery-3.6.0.min.js'),
|
|
|
- import('./jietu.js')
|
|
|
- ])
|
|
|
+ const [awsJs, jqJs, jieTuJs] = await Promise.all([
|
|
|
+ import('./aws-sdk-2.235.1.min.js'),
|
|
|
+ import('./jquery-3.6.0.min.js'),
|
|
|
+ import('./jietu.js')
|
|
|
+ ])
|
|
|
|
|
|
- // 创建script标签并注入JS文件
|
|
|
- const scripts = [
|
|
|
- { id: 'aws-sdk', content: awsJs.default || awsJs },
|
|
|
- { id: 'jquery', content: jqJs.default || jqJs },
|
|
|
- { id: 'jietu', content: jieTuJs.default || jieTuJs }
|
|
|
- ]
|
|
|
+ // 创建script标签并注入JS文件
|
|
|
+ const scripts = [
|
|
|
+ { id: 'aws-sdk', content: awsJs.default || awsJs },
|
|
|
+ { id: 'jquery', content: jqJs.default || jqJs },
|
|
|
+ { id: 'jietu', content: jieTuJs.default || jieTuJs }
|
|
|
+ ]
|
|
|
|
|
|
- scripts.forEach(script => {
|
|
|
+ scripts.forEach(script => {
|
|
|
// 检查是否已经注入过
|
|
|
- if (!iframeDoc.getElementById(script.id)) {
|
|
|
- const scriptElement = iframeDoc.createElement('script')
|
|
|
- scriptElement.id = script.id
|
|
|
- scriptElement.textContent = script.content
|
|
|
- iframeHead.appendChild(scriptElement)
|
|
|
+ if (!iframeDoc.getElementById(script.id)) {
|
|
|
+ const scriptElement = iframeDoc.createElement('script')
|
|
|
+ scriptElement.id = script.id
|
|
|
+ scriptElement.textContent = script.content
|
|
|
+ iframeHead.appendChild(scriptElement)
|
|
|
|
|
|
- console.log(`已注入 ${script.id} 到iframe中`)
|
|
|
- }
|
|
|
- })
|
|
|
+ console.log(`已注入 ${script.id} 到iframe中`)
|
|
|
+ }
|
|
|
+ })
|
|
|
|
|
|
- // 可选:在iframe中执行一些初始化代码
|
|
|
- try {
|
|
|
- iframe.contentWindow.eval(`
|
|
|
+ // 可选:在iframe中执行一些初始化代码
|
|
|
+ try {
|
|
|
+ iframe.contentWindow.eval(`
|
|
|
console.log('iframe中的JS环境已准备就绪');
|
|
|
// 这里可以添加一些初始化代码
|
|
|
`)
|
|
|
+ }
|
|
|
+ catch (evalError) {
|
|
|
+ console.warn('无法在iframe中执行代码:', evalError)
|
|
|
+ }
|
|
|
}
|
|
|
- catch (evalError) {
|
|
|
- console.warn('无法在iframe中执行代码:', evalError)
|
|
|
- }
|
|
|
}
|
|
|
- }
|
|
|
- else {
|
|
|
- console.warn('无法访问iframe内容,可能是跨域限制')
|
|
|
- }
|
|
|
+ else {
|
|
|
+ console.warn('无法访问iframe内容,可能是跨域限制')
|
|
|
+ }
|
|
|
+ }, 2000)
|
|
|
+
|
|
|
}
|
|
|
catch (error) {
|
|
|
console.error('注入JS到iframe失败:', error)
|