忘记了,喜欢一个人的感觉

Demon's Blog  »  程序设计  »  在InternetExplorer.Application中显示本地图片

在InternetExplorer.Application中显示本地图片

标签: imgInternetExplorer.ApplicationVBSVBScript图片

标题: 在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

随机文章:

  1. 利用WMI打造完美“三无”后门-终焉
  2. 用C语言实现PHP的base64_encode函数
  3. VBS实现Unicode(UTF-16)转UTF-8
  4. NETGEAR WNDRMAC路由器刷OpenWrt
  5. Windows 7 快速共享Internet无线网络

这篇文章发布于 2011年02月19日,星期六,00:36

在InternetExplorer.Application中显示本地图片的更多相关文章

  1. tomcat中显示本地图片①(未解决)

    <本模块文仅作为学习过程中的自我总结,有需要可参看,欢迎指导与提出建议,很多地方可能断章取义,理解不到位,虚心求学.谢谢!> 资料查阅原因:2018/7/10(做项目中显示详情页面,从数据 ...

  2. tomcat中显示本地图片①(已解决)

    解决方案 我直接放源码了. 原理就是:我虽然调用的是虚拟目录,但是会映射到对应路径的实际 第一步:(在tomcat的 server.xml中创建一个虚拟目录) 虚拟目录创建方式: <Contex ...

  3. Android 使用ContentProvider扫描手机中的图片,仿微信显示本地图片效果

    版权声明:本文为博主原创文章,未经博主允许不得转载. 转载请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/1873 ...

  4. Android ImageView显示本地图片

    Android ImageView 显示本地图片 布局文件 <?xml version="1.0" encoding="utf-8"?> <R ...

  5. SpringBoot之显示本地图片范例

    controller // 扫描指定目录下的图片进行展示 @RequestMapping("/showPics") public ModelAndView showPics(Mod ...

  6. Android 使用开源库StickyGridHeaders来实现带sections和headers的GridView显示本地图片效果

    大家好!过完年回来到现在差不多一个月没写文章了,一是觉得不知道写哪些方面的文章,没有好的题材来写,二是因为自己的一些私事给耽误了,所以过完年的第一篇文章到现在才发表出来,2014年我还是会继续在CSD ...

  7. Atitit. html 使用js显示本地图片的设计方案.doc

    Atitit. html 使用js显示本地图片的设计方案.doc 1.  Local mode  是可以的..web模式走有的不能兰.1 2. IE8.0 显示本地图片 img.src=本地图片路径无 ...

  8. Atitit. IE8.0 显示本地图片预览解决方案 img.src=本地图片路径无效的解决方案

    Atitit. IE8.0 显示本地图片预览解决方案 img.src=本地图片路径无效的解决方案 1. IE8.0 显示本地图片 img.src=本地图片路径无效的解决方案1 1.1. div来完成  ...

  9. Slog71_选取、上传和显示本地图片GET !(微信小程序之云开发-全栈时代3)

    ArthurSlog SLog-71 Year·1 Guangzhou·China Sep 12th 2018 ArthurSlog Page GitHub NPM Package Page 掘金主页 ...

随机推荐

  1. html5前端杂记

    首先是css的一些知识 毕竟自己懂得不多,但是一看资料.感觉似曾相识 <style> .red-text { color: red; } </style>//这里是css样式的 ...

  2. Android常见问题总结(二)

    1.布局文件LinearLayout线性布局添加内容报错. 解决方法: 线性布局LinearLayout中包裹的元素多余1个需要添加android:orientation属性. 2.android 的 ...

  3. JProfiler 9.1.1部署及使用

    软件准备: 官网下载地址:http://www.ej-technologies.com/download/jprofiler/files 软件部署: windows安装双击即可. 注册号: L-Lar ...

  4. PHP开发心得四

    1,php返回给html页面的Json数据不能含有回车符 某次用php编写查询数据库数据,以json格式返回给前端页面js文件,js文件以angularJS的函数调用处理的方式进行数据显示,但数据返回 ...

  5. 在自学css开始就遇到问题,“链入外部样式表”在多浏览器显示问题

    在自学css开始就遇到问题,“链入外部样式表”的习题,代码如下:A.被链入的CSS文件代码.css<style  type="text/css"><!--h1{b ...

  6. C#压缩文件夹至zip,不包含所选文件夹【转+修改】

    转自园友:jimcsharp的博文C#实现Zip压缩解压实例[转] 在此基础上,对其中的压缩文件夹方法略作修正,并增加是否对父文件夹进行压缩的方法.(因为笔者有只压缩文件夹下的所有文件,却不想将选中的 ...

  7. SqlBulkCopy实现大批量数据导入

    //自增列重新生成:SqlBulkCopy bc = new SqlBulkCopy(conn) //自增列保留原值:SqlBulkCopy bc = new SqlBulkCopy(conn,Sql ...

  8. Window提高_3.1练习_双进程守护

    双进程守护 当打开一个进程A的时候,此进程检测是否存在进程B,如果不存在就创建进程B. 进程B的作用是检测进程A是否被关闭,如果被关闭了,就再创建一个进程A. 双进程守护A.exe代码如下: #inc ...

  9. 最大子段和(洛谷P1115,动态规划递推)

    洛谷题目链接 题目赋值出来格式有问题,所以我就只放题目链接了 下面为ac代码 #include<bits/stdc++.h> #define ll long long using name ...

  10. CF450B Jzzhu and Sequences(矩阵加速)

    CF450B Jzzhu and Sequences 大佬留言:这.这.不就是矩乘的模板吗,切掉它!! You are given xx and yy , please calculate $f_{n ...