gpt4 book ai didi

google-chrome - 如何在 Chrome 中使用 vbscript 打开 Pdf 并通过在 url 中添加 # 进行搜索

转载 作者:行者123 更新时间:2023-12-04 08:38:08 25 4
gpt4 key购买 nike

再会,
我正在尝试使用 vbscript 打开 pdf url。 pdf 在本地电脑上。我正在使用 vbscript 打开 url 并使用 chrome。在我的 URL 中,我使用 #Search=Register 这将使 pdf 打开并搜索第一次出现的 Register。
我的问题是,即使我的 # 被编码为 %23,我的 Url 似乎也被 % 编码,然后 chrome pdf 预览不起作用。
我的 vbscript 代码:

Dim strChrome
Dim WShellChrome
Dim strUrl

Set WShellChrome = CreateObject("WScript.Shell")
strChrome = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
strUrl = "\\myserver/HelpDocumentation/Configuration - Company Configuration.pdf#Search=Register"

WShellChrome.Run chr(34) + strChrome + chr(34) & " " & chr(34) + strUrl + chr(34), 1, false
当我运行此代码时,它会使用以下网址打开 Chrome:
file://myserver/HelpDocumentation/Configuration%20-%20Company%20Configuration.pdf%23Search=Register
请注意发生的 % url 编码。 %20 是 空间 %23 是 #
然后浏览器找不到 pdf 网址,因为 # 被编码为 %23 .
如果我更改 %23 在浏览器 url 中输入 # 它可以工作并显示pdf。
看起来 %20(空格)在 url 中是可以的,但它不喜欢 %23(#)。
我需要 url 中的 # 来打开 pdf 并搜索特定的字符串。
如果我复制 url ,它似乎也不是 vbscript:
\\myserver/HelpDocumentation/Configuration - Company Configuration.pdf#Search=Register
并将其粘贴到我的 chrome url 中,它会自动将空格转换为 %20 并将 # 转换为 %23,但 acrobat 预览无法正常工作,因为它认为 %23 是文件名的一部分。
希望我说的有道理,不明白的请追问。

最佳答案

回复后我尝试了以下方法。
尝试使用 strUrl = escape(strUrl)但这导致 strUrl 被完全编码,即使是/和\斜杠。
然后我开始检查不同的网址,建议将我的/更改为\斜杠以及编码空格。这是我的结果。
当我使用没有编码空格的 url 时

"\\myserver\HelpDocumentation\Configuration - Company Configuration.pdf#Search=Register_"
在 chrome 中,它根本不编码,并且在 url 中的每个空格处都会打开一个新选项卡。 - 不工作。
当我使用
"\\myserver\HelpDocumentation\Configuration%20-%20Company%20Configuration.pdf#Search=Register_"
在 chrome 中,它更改为: file://myserver/HelpDocumentation/Configuration%2520-%2520Company%2520Configuration.pdf%23Search=Register_然后由于双重编码而无法工作。所以它添加了一个“文件:”,并再次对 url 进行编码,空格和 # 被编码。
当我使用
file:\\myserver\HelpDocumentation\Configuration%20-%20Company%20Configuration.pdf#Search=Register_
在 chrome 中它保持不变,结果它正在工作。因此,在开头附加的“文件:”和仅对 url 中的空格进行编码会有所不同。
我最终得到了以下代码。请注意 strUrl 是一个输入变量,例如我刚硬编码。我现在还检查它是否为 pdf,然后添加“文件:”,因为 url 可以是文件或报告 url。此代码有效。
Dim strChrome
Dim WShellChrome
Dim strUrl

Set WShellChrome = CreateObject("WScript.Shell")
strChrome = """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"""
strUrl = "\\myserver\HelpDocumentation\Configuration - Company Configuration.pdf#Search=Register_"

strUrl = Replace(strUrl, " ", "%20")

if(InStr(strUrl,".pdf")) Then
strUrl = "file:" + strUrl
End If

WShellChrome.Run strChrome & " " & ""+strUrl+"" , 1, false

关于google-chrome - 如何在 Chrome 中使用 vbscript 打开 Pdf 并通过在 url 中添加 # 进行搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64697875/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com