2013-01-31 176 views
0

如何獲得此代碼以使用Safari或Firefox?代碼打開IE瀏覽器,但需要Safari瀏覽器和Firefox

Public Function getGoogDistanceTime(startAddr As String, startCity As String, _ 
startState As String, startZip As String, endAddr As String, _ 
endCity As String, endState As String, endZip As String) As String 
Dim sURL As String 
Dim BodyTxt As String 
Dim apan As String 
Dim oXH As Object 
    sURL = "http://maps.google.com/maps?f=d&source=s_d&saddr=" 
    sURL = sURL & Replace(startAddr, " ", "+") & ",+" & Replace(startCity, " ", "+") & ",+" & startState 
    sURL = sURL & "&daddr=" & Replace(endAddr, " ", "+") & ",+" & Replace(endCity, " ", "+") & ",+" & endState 
    sURL = sURL & "&hl=en" 
    Set oXH = CreateObject("msxml2.xmlhttp") 
      With oXH 
       .Open "get", sURL, False 
       .Send 
       BodyTxt = .RESPONSETEXT 
      End With 

      apan = Application.WorksheetFunction.Trim(apan) 
      apan = Mid(BodyTxt, InStr(1, BodyTxt, "<div class=""altroute-rcol altroute-info"">") + 49, 200) 
      apan = Left(apan, InStr(1, apan, "</span> </div>") - 1) 
      apan = Replace(apan, "</span>", "") 
      apan = Replace(apan, "<span>", "") 
      getGoogDistanceTime = apan 
    Set oXH = Nothing 
End Function 

回答

0

您的代碼是用VBScript編寫的,這是一種僅限Internet Explorer的語言。您需要用JavaScript重寫它,這是所有瀏覽器都能理解的。

您還正在使用純IE代碼來執行AJAX,使用msxml2。這將需要更改爲使用更通用的AJAX代碼,使用XMLHttpRequest對象。

我不知道Application.WorksheetFunction.Trim()是什麼,但您需要找到一個JavaScript替代方案。

相關問題