Change chrome app window location, but not from main.js

无人久伴 提交于 2019-12-23 21:01:40

问题


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;
{

as a callback to the window.create function, and

click_Function(){
  curr_window.assign("html file");
}

in a

<script></script>

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?


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/17875410/change-chrome-app-window-location-but-not-from-main-js

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