个性化阅读
专注于IT技术分析

如何在Windows 10中使用命令行在Google Chrome中打开具有特定窗口大小的URL

在继续解决方案之前, 我们需要了解问题。如果你仔细阅读Chromium的文档或在命令行中使用可以在Chromium上设置的所有选项的列表, 你会很快发现可以使用–window-以特定窗口大小启动Chrome(铬)。尺寸标记, 例如, 要打开自定义尺寸的chrome, 只需在命令提示符下运行以下命令:

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --window-size=800, 600

可惜的是, 在默认安装的Chrome启动时, 它将具有最后一个用户拥有的最后一个窗口大小, 而不是我们在命令specifying上指定的窗口大小。发生这种情况是因为我们也没有更改命令的默认u​​ser-data-dir属性。用户数据目录包含配置文件数据, 例如历史记录, 书签和cookie, 以及其他按安装的本地状态。每个概要文件都是用户数据目录中的一个子目录(通常是默认目录)。可以使用命令上的–user-data-dir标志更改此设置。

打开一个URL

现在, 让我们解释一下你的目的, 理想情况下, 该命令应该只在一个具有自定义大小的窗口中打开一个新URL。在这种情况下, 我们只需将–user-data-dir更改为将在桌面中创建的自定义目录, 即可使用–chrome-frame标志和带有–app的URL指定框架窗口:

REM where:
REM --chrome-frame: specifies that the website should be opened in a single frame, without tabs.
REM --user-data-dir: a custom directory that stores the configuration of your new options (window-size)
REM --window-size: specify the width and height of the new window.
REM --app: the URL of the website that you are trying to show
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --chrome-frame --user-data-dir="C:\Users\your-username\Desktop\tmp-chrome" --window-size=800, 600 --app=https://bestfreehtmlcsstemplates.com

这将以所需的窗口大小(800×600)运行Google Chrome, 并打开指定的URL(bestfreehtmlcsstemplates.com)。值得一提的是, 你不应该使用鼠标来修改框架的大小, 而是关闭chrome并以新的大小再次运行命令。

请注意, 首次运行后, 将在user-data-dir目录中创建一些新文件:

Google Chrome用户数据目录临时目录

你可以删除它们, 但是每次运行命令时, 文件都会一次又一次地出现, 因此你可以简单地忽略此目录的存在。或者, 你可以使用系统的随机临时目录运行命令, 如下所示:

REM where "%tmp%\chrome_tmp_user_dir~%RANDOM%"
REM translates basically to a new random temporary directory
REM for example: "C:\Users\your-user\AppData\Local\Temp\chrom_tmp_user_dir~15034"
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --chrome-frame --user-data-dir="%tmp%\chrome_tmp_user_dir~%RANDOM%" --window-size=800, 600 --app=https://bestfreehtmlcsstemplates.com

这样, 你将永远不会看到存储chrome的tmp数据的目录, 它将始终作为全新的chrome实例运行!

编码愉快❤️!

赞(0)
未经允许不得转载:srcmini » 如何在Windows 10中使用命令行在Google Chrome中打开具有特定窗口大小的URL

评论 抢沙发

评论前必须登录!