代码打开IE但需要safari和Firefox

时间:2013-01-31 16:28:31

标签: firefox safari

如何让这段代码与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

1 个答案:

答案 0 :(得分:0)

您的代码是用VBScript编写的,VBScript是一种仅限Internet Explorer的语言。您需要在JavaScript中重写它,这是所有浏览器都能理解的。

您还使用仅使用IE的代码来执行AJAX,使用msxml2。这将需要使用XMLHttpRequest对象更改为使用更通用的AJAX代码。

我不知道Application.WorksheetFunction.Trim()是什么,但你需要找到一个JavaScript替代品。