问题描述
我做了一个窗口,有几个按钮。当我点击它们时,我有一个启动的功能。现在我的问题是如何更改(相同)窗口以显示另一个html文件?我试过了
I have made a window, with a couple of buttons. When I click them, I have a function which fires up. Now my question is how can I change the (same) window to show another html file? I have tried
function callback(a) {
curr_window = a.contentWindow.location;
{
作为window.create函数的回调,
as a callback to the window.create function, and
click_Function(){
curr_window.assign("html file");
}
in a
<script></script>
在HTML文件中,但这不起作用,因为(来自我的谷歌搜索)main.js isn在页面中执行,因此不共享它们的全局变量。那么如何使用onClick函数更改窗口的位置?
inside the HTML file, but that didn't work because (from my googling) main.js isn't executed in the page, so their global variables aren't shared. So how can I change the window's location using the onClick function?
推荐答案
您不应该直接更改窗口的Chrome应用中的位置信息。您可以更改的位置对象的唯一部分是引用文档中片段的href。
You are not supposed to be able to directly change a window's location in a Chrome App. The only part of the location object you can change is the href to reference a fragment in a document.
这是Chrome应用团队停止应用的明确设计决策来自页面之间导航的白色闪光。如果您查看,唯一的方法是创建并且需要该窗口应显示的URL。
This was an explicit design decision of the Chrome Apps team to stop apps from having the flash of white whilst it navigates between pages. If you look at the window api the only method is create and that takes the URL of what that window should display.
话虽如此,您可以在主窗口中加载iframe并进行更改。您只需要将iframe设置为窗口宽度和高度的100%。
That being said, you can load an iframe in the main window and change that. You would just need to set the iframe to be 100% of the width and height of the window.
这篇关于更改Chrome应用程序窗口位置,但不能更改main.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!