Open Chrome in a new window (Chrome app)

青春壹個敷衍的年華 提交于 2021-01-28 20:07:18

问题


I'm trying to create a chrome app that when i click on a button, it opens a new chrome window, at the moment it just opens a new tab.

html:

<html>
<head>
<script src="jquery-3.1.1.min.js"></script>
<script src="script.js"></script>
</head>

<body>

<button>Test</button>

</body>
</html>

JS:

$(document).ready(function() {
  $("button").click(function() {
    window.open(
      "https://www.google.com",
      "_blank",
      "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400"
    );
  });
});

回答1:


Sadly, there's no way to do that that I know of.

Using window.open in an app's context is a bit of a hack, but results in the URL being open in the user's default browser (not necessarily Chrome). There's no control as to how the browser chooses to open it.

There's a Chrome App specific API that was created specifically with "open a page in Chrome" in mind, chrome.browser. However, it still doesn't provide an option to open in a new window.


The closest you can get is to create your own "browser": an app window with a <webview> in it. Then you have full control over presentation, but it's not integrated with Chrome's profile and may require additional work to implement things like dialogs and browser controls. See the Browser sample app and <webview> documentation.




回答2:


You missed out " on the end of the line

window.open("https://www.google.com", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");



回答3:


this creates new window in chrome app

chrome.app.window.create('https://www.google.com', {
    id: "MyApp",
    outerBounds: {width: 400, height: 400}
});

If you want an external URL then u should use

<webview src="http://news.google.com/" width="640" height="480"></webview>

for more details on dynamically changing the src property, follow the Link



来源:https://stackoverflow.com/questions/40488271/open-chrome-in-a-new-window-chrome-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!