在InternetExplorer.Application中显示本地图片
Demon's Blog » 程序设计 » 在InternetExplorer.Application中显示本地图片
在InternetExplorer.Application中显示本地图片
标签: img, InternetExplorer.Application, VBS, VBScript, 图片
标题: 在InternetExplorer.Application中显示本地图片
作者: Demon
链接: http://demon.tw/programming/internetexplorer-application-img-src.html
版权: 本博客的所有文章,都遵守“署名-非商业性使用-相同方式共享 2.5 中国大陆”协议条款。
很久以前的问题了,一直没解决,今天无意中搜到了答案。
在InternetExplorer.Application对象中显示远程服务器上的图片是没有问题的:
Dim IE
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "about:blank"
IE.Document.write "<img src='http://demon.tw/demon.gif' />"
IE.Visible = True
然而,在IE默认的设置下,却无法显示本地图片:
Dim IE
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "about:blank"
IE.Document.write "<img src='D:/demon.gif' />"
IE.Visible = True
有人说要使用相对路径,有人说路径要用反斜杠
IE.Document.write "<img src='D:\demon.gif' />"
也有人说要加上协议名称
IE.Document.write "<img src='file:///D:/demon.gif' />"
还有人说加上协议名称并使用反斜杠
IE.Document.write "<img src='file:///D:\demon.gif' />"
我都试过了,没用,百思不得其解。
今天却无意中搜索到一段微软网站上的代码,终于豁然开朗:
Option Explicit
Dim objWshShell, objFSO, strVariableName, objExplorer, strScriptFileDirectory Set objWshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject") strVariableName = "WhateverYouWant"
strScriptFileDirectory = objFSO.GetParentFolderName(wscript.ScriptFullName) ' Displays the Internet Explorer informational message window.
DisplayIEwindow wscript.Sleep 4000 CloseIEwindow
Wscript.Quit ' ~$~----------------------------------------~$~
' FUNCTIONS & SUBROUTINES
' ~$~----------------------------------------~$~
Sub DisplayIEwindow
' Executes an Internet Explorer window.
Dim strIEregistryKey, strCheckAssociationsKey
strIEregistryKey = "NotExist" On Error Resume Next ' The following registry entry will enable local files such as .GIFs to be displayed using IE 7.0, but this setting will not take effect if the web browser is already open (there will be no error messages displayed if this is the case).
strIEregistryKey = objWshShell.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\blank\about") wscript.echo strIEregistryKey If strIEregistryKey = "NotExist" Then
objWshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\blank\about", 2, "REG_DWORD"
wscript.echo "escreve"
End If ' Attempts to temporarily prevent Internet Explorer checking to see if it is the default browser (storing the existing value to be restored after disaplying the script's IE window).
strCheckAssociationsKey = objWshShell.RegRead("HKCU\Software\Microsoft\Internet Explorer\Main\Check_Associations")
objWshShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Main\Check_Associations", "no", "REG_SZ" Set objExplorer = CreateObject ("InternetExplorer.Application")
objExplorer.Navigate "about:blank"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Left = 200
objExplorer.Top = 100
objExplorer.Width = 450
objExplorer.Height = 220
objExplorer.Visible = 1
objExplorer.Document.Body.Scroll = "no"
objExplorer.Document.Body.Style.Cursor = "wait"
objExplorer.Document.Title = "Window Title Name Goes Here" & String(50, ".") objExplorer.Document.Body.InnerHTML = "<img src='file:///" & strScriptFileDirectory & "\pro.gif' align='left'> " & "<b><font size='4'><font color='#008000'>" & strVariableName & " . . .</font></b><br>This application is currently being installed, and may take up to 5 minutes to complete.<p align='center'><font size='3'><b>Installation Start Time:</b> " & Time & "</p></p><p align='center'><font size='2'>*closing this window will <u>not</u> abort the installation<font color='#808080'><br> (this window will close automatically after the process completes)</font></font>" ' Attempts to make the open IE window active.
WScript.Sleep 1000
objWshShell.AppActivate "Window Title Name Goes Here"
WScript.Sleep 1001 ' Removes the added registry key setting used with IE 7.0 if it did not already exist.
If strIEregistryKey = "NotExist" Then
objWshShell.RegDelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\blank\"
End If ' Restores the original Check_Associations registry setting from the script's stored value.
objWshShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Main\Check_Associations", strCheckAssociationsKey, "REG_SZ"
End Sub ' ~$~----------------------------------------~$~
Sub CloseIEwindow
' Attemps to close the Internet Explorer window if it was opened by this script.
On Error Resume Next
objExplorer.Quit
End Sub
代码里的注释写得很详细,我就不解释了。什么?看不懂英文?那你点参考链接进去看看原文吧,代码以外的部分都是葡萄牙语,作者不用葡萄牙写注释已经很不错了。
图片显示的问题解决后,VBS也可以写出漂亮的WEB界面了。
参考链接:Script InternetExplorer.Application + img scr
随机文章:
- 利用WMI打造完美“三无”后门-终焉
- 用C语言实现PHP的base64_encode函数
- VBS实现Unicode(UTF-16)转UTF-8
- NETGEAR WNDRMAC路由器刷OpenWrt
- Windows 7 快速共享Internet无线网络
这篇文章发布于 2011年02月19日,星期六,00:36
在InternetExplorer.Application中显示本地图片的更多相关文章
- tomcat中显示本地图片①(未解决)
<本模块文仅作为学习过程中的自我总结,有需要可参看,欢迎指导与提出建议,很多地方可能断章取义,理解不到位,虚心求学.谢谢!> 资料查阅原因:2018/7/10(做项目中显示详情页面,从数据 ...
- tomcat中显示本地图片①(已解决)
解决方案 我直接放源码了. 原理就是:我虽然调用的是虚拟目录,但是会映射到对应路径的实际 第一步:(在tomcat的 server.xml中创建一个虚拟目录) 虚拟目录创建方式: <Contex ...
- Android 使用ContentProvider扫描手机中的图片,仿微信显示本地图片效果
版权声明:本文为博主原创文章,未经博主允许不得转载. 转载请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/1873 ...
- Android ImageView显示本地图片
Android ImageView 显示本地图片 布局文件 <?xml version="1.0" encoding="utf-8"?> <R ...
- SpringBoot之显示本地图片范例
controller // 扫描指定目录下的图片进行展示 @RequestMapping("/showPics") public ModelAndView showPics(Mod ...
- Android 使用开源库StickyGridHeaders来实现带sections和headers的GridView显示本地图片效果
大家好!过完年回来到现在差不多一个月没写文章了,一是觉得不知道写哪些方面的文章,没有好的题材来写,二是因为自己的一些私事给耽误了,所以过完年的第一篇文章到现在才发表出来,2014年我还是会继续在CSD ...
- Atitit. html 使用js显示本地图片的设计方案.doc
Atitit. html 使用js显示本地图片的设计方案.doc 1. Local mode 是可以的..web模式走有的不能兰.1 2. IE8.0 显示本地图片 img.src=本地图片路径无 ...
- Atitit. IE8.0 显示本地图片预览解决方案 img.src=本地图片路径无效的解决方案
Atitit. IE8.0 显示本地图片预览解决方案 img.src=本地图片路径无效的解决方案 1. IE8.0 显示本地图片 img.src=本地图片路径无效的解决方案1 1.1. div来完成 ...
- Slog71_选取、上传和显示本地图片GET !(微信小程序之云开发-全栈时代3)
ArthurSlog SLog-71 Year·1 Guangzhou·China Sep 12th 2018 ArthurSlog Page GitHub NPM Package Page 掘金主页 ...
随机推荐
- LR接口测试---基于http协议之get/post
get请求代码: //=====================get interface======================== 以http状态码方式: //获取返回的HTTP状态码判断请求 ...
- TASKCTL5.0日志乱码解决方案
从大学毕业到现在,做了不少银行外包项目,数据类的项目基本都用到taskctl调度产品,一直习以为然,觉得调度产品都应该是这样的,所以也没觉得怎样,直到后来有两个外包项目没用taskctl调度工具,要接 ...
- 踩过好多次的坑 - ajax访问【mango】项目的service
这个坑真的是踩过好多次了,好记性不如烂笔头,我总是太高估我的记忆力,这次真的是要写下来了. 项目是用的seam框架 + hibernate搭建的,架构是前辈们搭好的劳动成果,在配置service的访问 ...
- R函数详解
字符串连接函数paste 1.字符串连接:paste(..., sep = " ", collapse = NULL)sep表示分隔符,默认为空格.collapse表示如果不指定值 ...
- ssh多主机
#node1 HOST node1 HostName 10.10.10.10 Port 21 User ubuntu UseKeychain yes AddKeysToAgent yes #node2 ...
- 第一节:EasyUI样式,行内编辑,基础知识
一丶常用属性 $('#j_dg_left').datagrid({ url: '/Stu_Areas/Stu/GradeList', fit: true, // 自动适应父容器大小 singleSel ...
- org-table
Table of Contents 1. table 1.1. 创建方式 1.2. 重新对齐 1.3. 行列编辑 1.4. 区域 1.5. 计算 1.6. 其他的 1.7. 行宽度 1.8. 列分 ...
- Deepin系统关于每次启动终端都要输入source /etc/profile的问题
关于每次启动终端都要输入source /etc/profile的问题 当我在Deepin系统中下载了node以及npm之后,我为了将node导入到系统文件,使用了以下命令sudo gedit ``/e ...
- Python之list、tuple、dict、set
参考原文 廖雪峰Python PS:来看看Python中比较特殊的几种数据类型list.tuple.dict.set list list(列表)是Python内置的一种数据类型,它是一种有序.可变的集 ...
- script标签属性sync和defer
<script src="a.js" defer></script> 加了defer属性script标签的页面,运行流程如下: 1.浏览器开始解析HTM ...