问题
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