设置img.src时报错SCRIPT5:拒绝访问

本文详细介绍了在Internet Explorer 11中使用HTML5 Canvas绘制图片的方法,以及解决因图片路径格式不兼容导致的绘图错误问题。通过将图片路径中的反斜杠转换为正斜杠,确保了不同浏览器下的兼容性。

环境ie11

用canvas绘图

var ctxDom=document.getElementById("canvas")
 var context = ctxDom.getContext('2d');
    
    var imgObject = new Image();        
    imgObject.onload = function() {
        context.save();
        context.clearRect(0, 0, this.width, this.height);            
        context.scale(parseInt($('.pageBox').width())/rePaintScale,parseInt($('.pageBox').width())/rePaintScale);
        context.drawImage(imgObject, 0, 0);
        context.restore();

    }
    imgObject.onerror=function(){alert("error!")};
   //之前没有对图片地址进行转换

/**图片为默认的\\uploadfiles\\labels\\d27093db-43bb-11e9-adfb-1458d0d31cd4\\1\\454deaf2-e169-461c-b009-362831729837\\label.png**/

/***在有的电脑上可以直接设置src,显示,在我电脑上报: SCRIPT:拒绝访问错误;后经过排除就是路径转换问题***/

/*****猜想有些浏览器可以自动转换,有些可能不能自动转换,或者转换功能坏了,导致报错,总结还是不要偷懒,保证文件路径标准化****/
    var url=src.replace(/\\/g,"/");
    console.log(url);
    imgObject.src=url;

 

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="shortcut icon" href="Sources/logo.png"> <meta property="og:image" content="https://digimktgsolution.com/Housing-Authority-AI-Photo/Sources/logo.png"> <meta property="og:image:type" content="image/png"> <meta property="og:image:width" content="308"> <meta property="og:image:height" content="308"> <meta property="og:title" content="Housing-Authority-AI-Photo"> <meta property="og:description" content="Housing-Authority-AI-Photo"> <title>Housing-Authority-AI-Photo</title> <!-- 引入二维码生成库 --> <script src="https://cdn.jsdelivr.net/gh/davidshimjs/qrcodejs@gh-pages/qrcode.min.js"></script> <style> @keyframes heartbeat { 0% { transform: scale(1); } 50% { transform: scale(1.1); } 100% { transform: scale(1); } } .BG { position: relative; top: 0; left: 0; width: 1920px; height: 950px; } /* 图片网格样式 */ #imageGrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 15px; } .image-container { aspect-ratio: 3/2; overflow: hidden; border-radius: 6px; background-color: #f5f5f5; display: flex; align-items: center; justify-content: center; position: relative; cursor: pointer; /* 添加指针样式 */ transition: all 0.3s ease; } .image-container:hover { transform: translateY(-5px); box-shadow: 0 10px 20px rgba(0,0,0,0.2); } .image-container img { max-width: 100%; max-height: 100%; object-fit: contain; transition: transform 0.4s ease; } /* 加载动画 */ .image-container::before { content: ""; position: absolute; width: 30px; height: 30px; border: 3px solid rgba(0,0,0,0.1); border-top-color: #3498db; border-radius: 50%; animation: spin 1s linear infinite; opacity: 0; transition: opacity 0.3s; } .image-container.loading::before { opacity: 1; } @keyframes spin { to { transform: rotate(360deg); } } body { margin: 0; font-family: Arial, Helvetica, sans-serif; height: 100%; overflow: hidden; background-color: #e6939d; } .content { position: absolute; top: 14%; scale: 0.9; left: 3%; height: 810px; overflow-y: scroll; margin-top:6%; } .Preview { position: absolute; top: 28%; left: 12%; width: 39%; height: auto; border: 5px solid white; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); margin-top: 13%; } /* 页面切换动画 */ .page { position: absolute; top: 0; left: 0; width: 100%; height: 100%; transition: opacity 0.5s ease; } /* 返回按钮 */ .back-btn { position: absolute; top: 5%; left: 5%; color: white; border: none; padding: 10px 20px; border-radius: 50px; cursor: pointer; font-size: 16px; font-weight: bold; z-index: 100; margin-top: 40%; width: 10%; margin-left: -4%; } /* 二维码容器样式 */ #qrcodeContainer { position: absolute; top: 28%; right: 16%; width: 16%; height: auto; background: white; padding: 10px; border-radius: 10px; box-shadow: 0 5px 15px rgba(0,0,0,0.2); margin-top: 11%; } #qrcode { width: 100%; height: auto; } .qrcode-label { text-align: center; margin-top: 10px; font-size: 14px; font-weight: bold; color: #333; } </style> </head> <body> <div style="position: relative; left: 0; top: 0;"> <div id="HomePage" class="page"> <img src="Sources/GalleryBG.png" class="BG" width="1080" height="1920"> <div id="content" class="content"> <div id="imageGrid" class="imageGrid"></div> </div> </div> <div id="ScanPage" class="page" style="display: none;"> <img src="Sources/ScanBG.jpg" class="BG" width="1080" height="1920"> <div id="previewCon"> <img src="" class="Preview" id="Preview"> <img src="Sources/GallerybackBtn.png" id="back-btn" class="back-btn" onclick="showHomePage()"> <!-- 二维码容器 --> <div id="qrcodeContainer"> <div id="qrcode"></div> </div> </div> </div> </div> <script> // 全局变量存储当前选择的图片URL let selectedImageUrl = ""; let currentQRCode = null; // 存储当前二维码实例 // 页面切换函数 function showHomePage() { document.getElementById('HomePage').style.display = 'block'; document.getElementById('ScanPage').style.display = 'none'; } function showScanPage(imgUrl) { selectedImageUrl = imgUrl; document.getElementById('Preview').src = imgUrl; document.getElementById('HomePage').style.display = 'none'; document.getElementById('ScanPage').style.display = 'block'; // 生成二维码 generateQRCode(imgUrl); } // 生成二维码函数 function generateQRCode(imgUrl) { // 获取图片文件名(不含.jpg扩展名) const fileName = imgUrl.substring(imgUrl.lastIndexOf('/') + 1).replace('.jpg', ''); // 构造二维码内容 const qrContent = `https://digimktgsolution.com/Housing-Authority-AI-Photo/download.html?id=${fileName}`; // 清除之前的二维码 const qrcodeDiv = document.getElementById('qrcode'); qrcodeDiv.innerHTML = ''; // 销毁旧的二维码实例(如果存在) if (currentQRCode) { currentQRCode.clear(); } // 创建新的二维码 currentQRCode = new QRCode(qrcodeDiv, { text: qrContent, width: 300, height: 300, colorDark: "#000000", colorLight: "#ffffff", correctLevel: QRCode.CorrectLevel.H }); } // 示例图片URL数组 var imageUrls = []; let da = {} // 获取图片数据 fetch("GetImage.php", { method: "POST", headers: { "Content-Type": "application/json; charset = utf-8" }, body: JSON.stringify(da) }).then(function (response) { return response.text(); }).then(function (data) { imageUrls = data.split('*'); console.log('Loaded images:', imageUrls.length - 1); const container = document.getElementById('imageGrid'); // 逆序数组(最后一张在最前) [...imageUrls].reverse().forEach(url => { if (url) { const imgContainer = document.createElement('div'); imgContainer.className = 'image-container loading'; const img = new Image(); img.src = url; img.alt = "Gallery image"; img.loading = "lazy"; // 添加点击事件监听 imgContainer.addEventListener('click', function() { showScanPage(url); }); img.onload = function () { imgContainer.classList.remove('loading'); if (img.naturalHeight > img.naturalWidth) { imgContainer.classList.add('portrait'); } }; img.onerror = function () { imgContainer.classList.remove('loading'); console.error('Image load failed:', url); img.src = 'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 24 24"><rect width="24" height="24" fill="%23f0f0f0"/><text x="50%" y="50%" dominant-baseline="middle" text-anchor="middle" font-family="monospace" font-size="10px">加載失敗</text></svg>'; }; imgContainer.appendChild(img); container.appendChild(imgContainer); } }); }).catch(function(error) { console.error('Fetch error:', error); }); </script> </body> </html> js使用以上代碼,當開啓”ScanPage“後進行60秒倒數,倒數完畢則回到”HomePage“,點擊返回按鈕也回到”HomePage“,當再次點擊其他圖片開啓”ScanPage“後重新倒數60秒。倒數顯示於”previewCon“裏面的二維碼div下面
10-31
<template> <div class="conversation-container"> <div class="conversation-list"> <div class="conversation-list-item"> <div class="conversation-list-title">待接入 {{ pendingConversations.length }}</div> <div class="conversation-list-body"> <router-link tag="div" :to="chat(conversation)" replace v-for="(conversation, key) in pendingConversations" :key="key"> <div class="conversation-item"> <div class="conversation-item-head"> <img :src="conversation.data.avatar" class="conversation-item-avatar" /> </div> <div class="item-info"> <div class="item-info-name">{{ conversation.data.name }}</div> <div v-if="conversation.lastMessage.type === 'text'" class="item-info-message"> {{ conversation.lastMessage.payload.text }} </div> <div v-else-if="conversation.lastMessage.type === 'image'" class="item-info-message">[图片消息]</div> <div v-else-if="conversation.lastMessage.type === 'video'" class="item-info-message">[视频消息]</div> <div v-else-if="conversation.lastMessage.type === 'audio'" class="item-info-message">[语音消息]</div> <div v-else-if="conversation.lastMessage.type === 'order'" class="item-info-message">[自定义消息:订单] </div> <div v-else-if="conversation.lastMessage.type === 'CS_END'" class="item-info-message">会话已结束</div> <div v-else-if="conversation.lastMessage.type === 'CS_ACCEPT'" class="item-info-message">接入成功</div> <div v-else-if="conversation.lastMessage.type === 'CS_TRANSFER'" class="item-info-message"> {{ conversation.lastMessage.senderId === currentAgent.id ? `已转接给` + conversation.lastMessage.payload.transferTo.data.name : '已接入来自' + conversation.lastMessage.senderData.name + '的转接' }} </div> <div v-else class="item-info-message">[未识别内容]</div> </div> </div> </router-link> </div> </div> <div class="conversation-list-item"> <div class="conversation-list-title">已接入 {{ conversations.length }}</div> <div v-if="conversations.length" class="conversation-list-body"> <router-link tag="div" :to="chat(conversation)" replace v-for="(conversation, key) in conversations" :key="key"> <div class="conversation-item" @contextmenu.prevent.stop="e => showRightClickMenu(e, conversation)"> <div class="conversation-item-head"> <img :src="conversation.data.avatar" class="conversation-item-avatar" /> <span v-if="conversation.unread" class="conversation-item-unread">{{ conversation.unread }}</span> </div> <div class="conversation-item-info"> <div class="item-info-top"> <div class="item-info-name">{{ conversation.data.name }}</div> <div class="item-info-time">{{ formatDate(conversation.lastMessage.timestamp) }}</div> </div> <div class="item-info-bottom"> <div v-if="conversation.lastMessage.status === 'sending'" class="item-info-sending"></div> <div v-if="conversation.lastMessage.status === 'fail'" class="item-info-failed"></div> <div v-if="conversation.lastMessage.type === 'text'" class="item-info-message"> {{ conversation.lastMessage.senderId === currentAgent.id ? '你' : conversation.lastMessage.senderData.name }}: {{ conversation.lastMessage.payload.text }} </div> <div v-else-if="conversation.lastMessage.type === 'image'" class="item-info-message">[图片消息]</div> <div v-else-if="conversation.lastMessage.type === 'video'" class="item-info-message">[视频消息]</div> <div v-else-if="conversation.lastMessage.type === 'audio'" class="item-info-message">[语音消息]</div> <div v-else-if="conversation.lastMessage.type === 'order'" class="item-info-message">[自定义消息:订单] </div> <div v-else-if="conversation.lastMessage.type === 'CS_END'" class="item-info-message">会话已结束</div> <div v-else-if="conversation.lastMessage.type === 'CS_ACCEPT'" class="item-info-message">接入成功</div> <div v-else-if="conversation.lastMessage.type === 'CS_TRANSFER'" class="item-info-message"> {{ conversation.lastMessage.senderId === currentAgent.id ? `已转接给` + conversation.lastMessage.payload.transferTo.data.name : '已接入来自' + conversation.lastMessage.senderData.name + '的转接' }} </div> <div v-else class="item-info-message">[未识别内容]</div> </div> </div> </div> </router-link> </div> </div> <div v-if="rightClickMenu.visible" :style="{ 'left': rightClickMenu.x + 'px', 'top': rightClickMenu.y + 'px' }" class="action-box"> <div class="action-item" @click="topConversation">{{ rightClickMenu.conversation.top ? '取消置顶' : '置顶' }}</div> <div class="action-item" @click="deleteConversation">删除聊天</div> </div> </div> <div class="conversation-main"> <router-view :key="$route.params.id"></router-view> </div> </div> </template> <script setup> import { ref, onMounted, onBeforeUnmount } from 'vue'; import { useRouter, useRoute } from 'vue-router'; import { formatDate } from '../utils/utils.js'; import GoEasy from 'goeasy'; // 引入真实的 GoEasy SDK import { useCounterStore } from '../stores/counter.js' const router = useRouter(); const route = useRoute(); // 定义响应式数据 const pendingConversations = ref([]); const conversations = ref([]); const rightClickMenu = ref({ conversation: null, visible: false, x: null, y: null, }); const currentAgent = ref(null); // 初始化 GoEasy const goEasy = GoEasy.getInstance({ host: 'hangzhou.goeasy.io', //应用所在的区域地址: 【hangzhou.goeasy.io |singapore.goeasy.io】 appkey: 'BC-f00d5ee0720d4dab888ca1b5536483ab', // common key, modules: ['im'], }); console.log('GoEasy initialized:', goEasy); console.log('GoEasy IM module:', goEasy.im); // 检查 IM 模块是否存在 // 其他代码保持不变... const loadConversations = () => { goEasy.im.pendingConversations({ onSuccess: (result) => { console.log('待接入会话:', result.content.conversations); renderPendingConversations(result.content); }, onFailed: (error) => { console.log('获取待接入列表失败:', error); }, }); goEasy.im.latestConversations({ onSuccess: (result) => { console.log('已接入会话:', result.content.conversations); renderLatestConversations(result.content); }, onFailed: (error) => { console.log('获取已接入列表失败:', error); }, }); }; const listenConversationUpdate = () => { // 监听会话列表变化 goEasy.im.on(goEasy.IM_EVENT.CONVERSATIONS_UPDATED, renderLatestConversations); goEasy.im.on(goEasy.IM_EVENT.PENDING_CONVERSATIONS_UPDATED, renderPendingConversations); }; const renderPendingConversations = (content) => { pendingConversations.value = content.conversations; }; const renderLatestConversations = (content) => { conversations.value = content.conversations; }; const chat = (conversation) => { return { path: `/conversations/chat/${conversation.id}`, query: { name: conversation.data.name, avatar: conversation.data.avatar, }, }; }; const showRightClickMenu = (e, conversation) => { rightClickMenu.value.conversation = conversation; rightClickMenu.value.visible = true; rightClickMenu.value.x = e.pageX; rightClickMenu.value.y = e.pageY; }; const hideRightClickMenu = () => { rightClickMenu.value.visible = false; }; const topConversation = () => { const conversation = rightClickMenu.value.conversation; const description = conversation.top ? '取消置顶' : '置顶'; goEasy.im.topConversation({ top: !conversation.top, conversation: conversation, onSuccess: () => { console.log(description, '成功'); }, onFailed: (error) => { console.log(description, '失败:', error); }, }); }; const deleteConversation = () => { if (!rightClickMenu.value.conversation.ended) { alert('删除失败:会话尚未结束'); return; } if (confirm('确认要删除这条会话吗?')) { goEasy.im.removeConversation({ conversation: rightClickMenu.value.conversation, onSuccess: () => { console.log('删除会话成功'); }, onFailed: (error) => { console.log(error); }, }); } }; onMounted(() => { // 隐藏 Conversation 右键菜单 document.addEventListener('click', hideRightClickMenu); // 获取当前客服信息 currentAgent.value = useCounterStore().currentAgent; console.log(currentAgent.value); // 监听 GoEasy 连接状态 goEasy.connect({ onSuccess: () => { console.log('GoEasy connected successfully'); // 确保用户信息存在 if (!currentAgent.value || !currentAgent.value.id || !currentAgent.value.name || !currentAgent.value.avatar) { console.error('Agent information is incomplete'); return; } // 登录IM goEasy.im.login({ id: currentAgent.value.id, // 必须 data: { // 必须 name: currentAgent.value.name, avatar: currentAgent.value.avatar, // 添加其他必要字段 }, onSuccess: () => { console.log('IM login success'); listenConversationUpdate(); loadConversations(); }, onFailed: (error) => { console.error('IM login failed:', error); } }); }, onFailed: (error) => { console.error('GoEasy connection failed:', error); } }); }); </script> <style scoped> .conversation-container { width: 100%; height: 100%; display: flex; background: #FFFFFF; } .conversation-list { width: 220px; border-right: 1px solid #eee; display: flex; flex-direction: column; padding: 10px; position: relative; } .conversation-list-title { font-size: 15px; margin: 5px 10px; color: rgba(0, 0, 0, 0.9); } .conversation-list-body { overflow-y: auto; max-height: 350px; scrollbar-width: none; -ms-overflow-style: none; } .conversation-list-body::-webkit-scrollbar { display: none; } .action-box { width: 100px; height: 60px; background: #ffffff; border: 1px solid #cccccc; position: fixed; z-index: 100; border-radius: 5px; } .action-item { padding-left: 15px; line-height: 30px; font-size: 13px; color: #262628; cursor: pointer; } .action-item:hover { background: #dddddd; } .conversation-item { display: flex; padding: 10px; cursor: pointer; } .conversation-item-head { position: relative; margin-right: 5px; } .conversation-item-avatar { width: 40px; height: 40px; border-radius: 4px; } .conversation-item-unread { position: absolute; top: -9px; right: -9px; width: 18px; height: 18px; line-height: 18px; border-radius: 50%; text-align: center; color: #fff; font-size: 12px; background-color: #fa5151; } .conversation-item-info { flex: 1; display: flex; flex-direction: column; justify-content: space-between; } .item-info-top { display: flex; justify-content: space-between; align-items: center; } .item-info-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; word-break: break-all; font-size: 15px; width: 80px; line-height: 25px; color: #333333; } .item-info-time { color: #666666; font-size: 12px; } .item-info-bottom { display: flex; align-items: center; } .item-info-message { font-size: 12px; line-height: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 150px; color: #606266; } .item-info-failed { background: url("../assets/images/failed.png") no-repeat center; background-size: 12px; width: 12px; height: 12px; margin-right: 2px; } .item-info-sending { background: url("../assets/images/pending.gif") no-repeat center; background-size: 12px; width: 12px; height: 12px; margin-right: 2px; } .router-link-active { background: #eeeeee; border-radius: 5px; } .conversation-main { flex: 1; background: #FFFFFF; } </style>我在用GoEasy实现即通讯报错code: 400, content: 'data: id and data are required for IM module
06-10
<template> <view class="wrap"> <view class="dev-area"> <view class="dev-cart"> <view class=""> <view class="dev-name">湿度</view> <image class="dev-logo" src="/static/humi.png" mode=""></image> </view> <view class="dev-data">{{humi}} %</view> </view> <view class="dev-cart"> <view class=""> <view class="dev-name">温度</view> <image class="dev-logo" src="/static/temper.png" mode=""></image> </view> <view class="dev-data">{{temp}} ℃</view> </view> <view class="dev-cart"> <view class=""> <view class="dev-name">台灯</view> <image class="dev-logo" src="/static/lamp.png" mode=""></image> </view> <switch :checked="led" @change="onLedSwitch" foreColor="#00ff7f"/> </view> <view class="dev-png-hello"> <view class=""> <image class="dev-hello" src="/static/nihao.png" mode=""></image> </view> </view> </view> </view> </template> <script> const { createCommonToken } = require('@/key.js') export default { data() { return { temp: '', humi: '', led: true, token: '', } }, onLoad() { const params = { access_key: 'M8tHI413Uy0rYwf5K5E1yVvDY1+LzwtJx9XbNdnFd1k=', version: '2022-05-01', productid: 'I0byo2uxi9', } this.token = createCommonToken(params); }, onShow() { this.fetchDevData(); setInterval(()=>{ this.fetchDevData(); },3000) }, methods: { fetchDevData() { uni.request({ url: 'https://iot-api.heclouds.com/thingmodel/query-device-property', //仅为示例,并非真实接口地址。 method: 'GET', data: { product_id: 'I0byo2uxi9', device_name: 'd1' }, header: { 'authorization': this.token //自定义请求头信息 }, success: (res) => { console.log(res.data); this.temp = res.data.data[2].value; this.humi = res.data.data[0].value; this.led = res.data.data[1].value === 'true'; } }); }, onLedSwitch(event) { console.log(event.detail.value); let value = event.detail.value; uni.request({ url: 'https://iot-api.heclouds.com/thingmodel/set-device-property', //仅为示例,并非真实接口地址。 method: 'POST', data: { product_id: 'I0byo2uxi9', device_name: 'd1', params: { "led": value } }, header: { 'authorization': this.token //自定义请求头信息 }, success: () => { console.log('LED ' + (value ? 'ON' : 'OFF') + ' !'); } }); } } } </script> <style> .wrap { padding: 30rpx; } .dev-area { display: flex; justify-content: space-between; flex-wrap: wrap; } .dev-cart { height: 150rpx; width: 320rpx; border-radius: 30rpx; margin-top: 30rpx; display: flex; justify-content: space-around; align-items: center; box-shadow: 0 0 15rpx #ccc; } .dev-name { font-size: 20rpx; text-align: center; color: #6d6d6d; } .dev-logo { width: 70rpx; height: 70rpx; margin-top: 10rpx; } .dev-data { font-size: 50rpx; color: #6d6d6d; } .dev-hello { width: 150rpx; height: 150rpx; margin-top: 10rpx; } .dev-png-hello { height: 150rpx; width: 320rpx; margin-top: 30rpx; display: flex; justify-content: space-around; align-items: center; } <div class="video-wrapper"> <img :src="videoUrl" alt="实监控" class="video-stream" @error="handleVideoError" > <div v-if="error" class="error-message"> 视频连接失败,请检查设备 </div> </div> </div> <script> export default { data() { return { videoUrl: "http://192.168.241.42", error: false }; }, methods: { handleVideoError() { this.error = true; } } }; </script> <style scoped> .app-container { display: flex; flex-direction: column; min-height: 100vh; } .video-wrapper { margin-top: auto; display: flex; justify-content: center; padding: 20px 0; background: #2c3e50; } .video-stream { max-width: min(800px, 90%); max-height: 50vh; border-radius: 8px; box-shadow: 0 0 20px rgba(0,0,0,0.5); } </style> (178:40) Missed semicolon 22:40:09.783 176 | data() { 22:40:09.783 177 | return { 22:40:09.783 > 178 | videoUrl: "http://192.168.241.42", 22:40:09.783 | ^ 22:40:09.783 179 | error: false 22:40:09.783 180 | }; 是因为我没开哪个esp32cam吗
最新发布
12-28
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值