javascript 在没有标签和其他菜单项的情况下打开 Chrome 或 Firefox,并设置屏幕位置和大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26147233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 05:34:34  来源:igfitidea点击:

Open Chrome or Firefox without tabs and other menu items and with a set screen position and size

javascripthtmlgoogle-chromefirefox

提问by vSteve

I need to startup either Chrome or Firefox in a set location, with a set size and without the tabs and other menu items. The ultimate goal is a desktop icon I can click to get a window X wide by Y tall at x,y on my desktop showing a particular page, without making these settings permanent for the browser.

我需要在设置的位置启动 Chrome 或 Firefox,设置大小并且没有选项卡和其他菜单项。最终目标是一个桌面图标,我可以单击以在我的桌面上显示特定页面的 x,y 处获得一个 X 宽 Y 高的窗口,而无需使这些设置对浏览器永久有效。

This is going to be a small window placed in the corner of a desktop showing an AJAX page that is updating throughout the day.

这将是一个放置在桌面角落的小窗口,显示一个全天都在更新的 AJAX 页面。

I can't seem to find any option for either of these browsers.

我似乎无法为这些浏览器中的任何一个找到任何选项。

回答by Makyen

In Firefox:

在 Firefox 中:

You can find details of the Firefox "Command Line Options" on MDN.

您可以在 MDN 上找到 Firefox“命令行选项”的详细信息。

It appears you can not do exactly what you desire, if you want to continue to have the page opened under your normal profile and without having your normal use of that profile disturbed. If you are willing to use a separate profile which is used only for this task, then you can accomplish what you desire. Using another profile is not a big deal. I commonly have more than one running at a time, and even use different versions of Firefox running at the same time under different profiles.

如果您想继续在您的正常配置文件下打开该页面并且不干扰您对该配置文件的正常使用,那么您似乎无法完全按照您的意愿行事。如果您愿意使用仅用于此任务的单独配置文件,那么您可以完成您想要的。使用另一个配置文件没什么大不了的。我通常一次运行多个,甚至在不同的配置文件下同时运行不同版本的 Firefox。

Using a separate profile and add-ons:

使用单独的配置文件和附加组件:

To create a new profile see: Use the Profile Manager to create and remove Firefox profilesor Multiple Firefox profiles. Create a profile, choose a name.

要创建新的配置文件,请参阅:使用配置文件管理器创建和删除 Firefox 配置文件多个 Firefox 配置文件。创建配置文件,选择一个名称。

You will need some add-ons:

您将需要一些附加组件:

  • Hide Navigation Bar(change options (Tools->Add-ons then "Extensions" and the "options button for this extension. Select "When Firefox starts: Hide the Navigation Bar")
  • Hide Tabbar(change options to select "Auto hide when only one tab is open")
  • 隐藏导航栏(更改选项(工具->附加组件,然后是“扩展”和“此扩展的选项按钮。选择“Firefox 启动时:隐藏导航栏”)
  • 隐藏标签栏(更改选项以选择“仅打开一个标签时自动隐藏”)

There may be others you could use, but the combination of these two worked when I tested it.

可能还有其他的你可以使用,但是当我测试它时,这两者的组合是有效的。

Go to the page you want to see. Adjust the size and position of the window to what you desire. By right clicking the mouse in the toolbar area de-select "Menu Bar" and "Bookmarks Toolbar". Close Firefox. Firefox should automatically remember the size and location of the window.

转到您要查看的页面。根据需要调整窗口的大小和位置。通过在工具栏区域右键单击鼠标,取消选择“菜单栏”和“书签工具栏”。关闭火狐。Firefox 应该自动记住窗口的大小和位置。

Create a shortcut:

创建快捷方式:

  "C:\Program Files\Mozilla Firefox\firefox.exe" -no-remote -P "My Profile Name" -url "http://the page I want to see"

Click on the shortcut. That should work.

单击快捷方式。那应该有效。

Shameless plug: If you want the icon for the window to be different so you can tell the windows apart in the taskbar, you could use: Change Profile's Window Icons. An extension whicht arose from my answer to a stackoverflow question. If you do change the icon, you will probably want to change the properties for the shortcut to point to the icon you use.

无耻的插件:如果您希望窗口的图标不同,以便您可以在任务栏中区分窗口,您可以使用:更改配置文件的窗口图标我对一个 stackoverflow 问题的回答产生了一个扩展。如果您确实更改了图标,您可能希望更改快捷方式的属性以指向您使用的图标。

Getting close to what you want using your current profile without disturbing it:

使用当前配置文件接近您想要的内容而不打扰它:

Without using an add-on you can come close. [Note: all were tested in Firefox and a Windows operating system assumed (for file paths).]

无需使用附加组件,您就可以接近。[注意:所有这些都在 Firefox 中进行了测试,并且假定使用 Windows 操作系统(对于文件路径)。]

You could use a bookmarkletto open a static URL in a limited window :

您可以使用书签在有限窗口中打开静态 URL:

javascript:void(window.open("http://www.google.com","_blank","outerWidth=400,outerHeight=200,top=500,left=600,menubar=no,toolbar=no,location=no,personalbar=no,status=no,resizable"))

or the URL you are currently viewing:

或您当前查看的网址:

javascript:void(window.open(location.href,"_blank","outerWidth=400,outerHeight=200,top=500,left=600,menubar=no,toolbar=no,location=no,personalbar=no,status=no,resizable"))

You can have the window open from a desktop shortcut, but in order to have the window with a limited interface you will end up with a normal size window which you will have to close (scripts are not permitted to close windows which are not opened by a script). You would need to use an html file on your machine to contain the script to open the appropriate URL.

您可以从桌面快捷方式打开窗口,但为了让窗口具有有限的界面,您最终会得到一个正常大小的窗口,您必须关闭该窗口(脚本不允许关闭未被打开的窗口)一个脚本)。您需要使用机器上的 html 文件来包含打开相应 URL 的脚本。

Note the first time you do this Firefox will inform you that it blocked a popup. You will need to permit popups from that file URL.

请注意,您第一次执行此操作时 Firefox 会通知您它阻止了一个弹出窗口。您将需要允许来自该文件 URL 的弹出窗口。

Example HTML file (example assumes it is located at: C:\open_location.html):

示例 HTML 文件(示例假设它位于:C:\open_location.html):

<head>
    <script class="code" type="text/javascript">
        var features =  ""  
                        + "menubar=no,toolbar=no,location=no,personalbar=no"
                        + ",status=no,chrome=yes,resizable,centerscreen"
                        //+ ",width=400"        //Width of content window
                        //+ ",height=200"       //Height of content window
                        + ",outerWidth=400"   //Width of window
                        + ",outerHeight=200"  //Height of window
                        + ",top=500"
                        + ",left=600"
                        ;
        window.open("http://www.google.com/","_blank",features);
        //Can only close windows opened by script.
        //window.close();
    </script>
</head>
<body>
</body>

You could then use a shortcut that opens the URL of that file:

然后,您可以使用打开该文件 URL 的快捷方式:

"C:\Program Files\Mozilla Firefox\firefox.exe" -url "file://C:/open_location.html"

I would suggest using a separate profile:

我建议使用单独的配置文件:

"C:\Program Files\Mozilla Firefox\firefox.exe" -no-remote -P "My Profile Name" -url "file://C:/open_location.html"

You can get rid of the URL bar from all of the above by setting dom.disable_window_open_feature.location=falsein about:config. However, if you do that I recommend using a different profile which is used for this purpose only as you normally don't want to do such for normal use.

您可以通过dom.disable_window_open_feature.location=falseabout:config. 但是,如果您这样做,我建议您使用不同的配置文件,该配置文件仅用于此目的,因为您通常不希望在正常使用中这样做。