2012-05-31 36 views
1

我正在使用VBScripta創建一個新的Internet Explorer窗口並顯示一個表單。 我想添加圖像到IE窗口,但我無法添加任何圖像。反而出現一個帶有小十字的盒子。 我在這裏發現了一個類似的查詢「Displaying an image in a VBScript MsgBox」,但提供的解決方案從網絡加載圖像(其工作),但我希望它從本地文件夾(不工作)。 有人可以幫我解決這個問題嗎?非常感謝:)在使用VBScipt打開的IE窗口中顯示圖像

Set objIE = CreateObject("InternetExplorer.Application") 
With objIE  
.Navigate "C:\Users\NA34242\Documents\SAP\Pages\GetTRs.html"  
.ToolBar = False  
.StatusBar = False  
.Left = 100  
.Top = 100  
.Width = 200  
.Height = 200  
.Visible = True  
.Document.Title = "Form"  
.Document.Body.InnerHTML = "<img src=""C:\images.png"" height=100 width=100>" 
End With 

回答

0

我很抱歉,但這種做法不會與大多數的瀏覽器工作,這是一個安全問題,你只能使用URI的爲IMG.src 你可以做的是導航到文件本身並使其可見,如果你需要在頁面上的其他東西,你將不得不在另一個框架中。

這是我採用的腳本來顯示我的位置c:驅動器的圖像。有了show sub,你可以顯示文字,但不是你的IMG

dim oIe 
InitIE 500, 500 
oIe.navigate "file:///C|/Users/peter/butterfly.png" 
'--- ---' 
Sub InitIE(iWidth,iHeight) 
    Dim iLeft, iTop 
    On error resume next 
    Set oIe = WScript.CreateObject("InternetExplorer.Application", "IE_") 
    If Err.Number <> 0 Then 
    WScript.CreateObject("WScript.Shell").Popup("Error:" & Err.description) 
    Wscript.Quit 
    Else 
    With oIe 
     .Visible = False 
     .TheaterMode = True 
     .FullScreen = True 
     iLeft = (.width - iWidth)/2 
     iTop = (.Height - iHeight)/2 
     .FullScreen = False 
     .TheaterMode = False        
     .MenuBar = True 
     .ToolBar = False 
     .StatusBar = True 
     .AddressBar = False 
     .navigate "about:blank" 
     .Width = iWidth 
     .Height = iHeight 
     .Left = iLeft 
     .Top = iTop 
     .Resizable = True 
     .Visible = True 
     .document.focus()         
    End With 
    End If 
End Sub 
'--- ---' 
Sub Show(ByVal sText) 
    If IEReady() Then 
    oIe.Document.body.innerHTML = oIe.Document.body.innerHTML & sText & "<br>" 
    iLengte = iLengte + 300 
    oIe.Document.parentWindow.scroll 0, iLengte 
    End If 
End Sub 
'--- ---' 
Function IEReady() 
    IEReady = False 
    If TypeName(oIe) <> "Object" Then 
    If oIe.ReadyState = 4 Then 
     IEReady = True 
    End If 
    End If 
End Function 
'--- ---' 
Sub CloseIE 
    oIe.Quit 
    Set oIe = Nothing 
End Sub