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

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. 60查找nanopim1plus的HDMI为720p输出的问题

    60查找nanopim1plus的HDMI为720p输出的问题 大文实验室/大文哥 壹捌陆捌零陆捌捌陆捌贰 21504965 AT qq.com 完成时间:2017/12/5 17:51 版本:V1. ...

  2. ListView用法

    public class MainActivity extends Activity implements OnItemClickListener, OnScrollListener { privat ...

  3. Android开发笔记(4)——MainActivity.java文件修改&布局嵌套

    笔记链接:http://www.cnblogs.com/igoslly/p/6805020.html         笔记以开发名为CoffeeOrder的app活动为线索,介绍app如何从功能设计→ ...

  4. Angular——单页面与路由的使用

    单页面 SPA(Single Page Application)指的是通单一页面展示所有功能,通过Ajax动态获取数据然后进行实时渲染,结合CSS3动画模仿原生App交互,然后再进行打包(使用工具把W ...

  5. MyEclipse 快捷键大全(@Hcy)

    MyEclipse 快捷键1(CTRL)-------------------------------------Ctrl+1 快速修复Ctrl+D: 删除当前行 Ctrl+Q  定位到最后编辑的地方 ...

  6. js延时加载的方法

    js的延迟加载有助与提高页面的加载速度,以下是延迟加载的几种方法: 1.使用setTimeout延迟方法的加载时间 延迟加载js代码,给网页加载留出更多时间 <script type=" ...

  7. java虚拟机(四)--内存溢出、内存泄漏、SOF

    学习了java运行时数据区,知道每个内存区域保存什么数据,可以参考:https://www.cnblogs.com/huigelaile/p/diamondshine.html,然后了 解内存溢出和内 ...

  8. Educational Codeforces Round 57 (Rated for Div. 2) 前三个题补题

    感慨 最终就做出来一个题,第二题差一点公式想错了,又是一波掉分,不过我相信我一定能爬上去的 A Find Divisible(思维) 上来就T了,后来直接想到了题解的O(1)解法,直接输出左边界和左边 ...

  9. TestNG多线程测试-注解方式实现

    用@Test(invocationCount = x,threadPoolSize = y)声明,invocationCount表示执行次数,threadPoolSize表示线程池大小. packag ...

  10. Flask保存或解压上传的文件

    import os import uuid import shutil import zipfile from flask import Flask, render_template, request ...