如何在不创建新窗口的情况下导航到chrome应用程序中的不同页面? [英] How to navigate to different pages in a chrome app without creating a new window?

查看:63
本文介绍了如何在不创建新窗口的情况下导航到chrome应用程序中的不同页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Chrome应用包含两个页面A1.html和A2.html.如何在不创建新窗口的情况下从A1.html导航到A2.html?

My Chrome app contains two pages A1.html and A2.html. How can i navigate from A1.html to A2.html without creating a new window?

A1.html页包含10个div,A2.html页包含指向A1.html的反向链接.我需要在按下A2.html中的反向链接时直接加载A1.html的特定div.

The page A1.html contains 10 div's and A2.html contains a back link to A1.html. My need is to load directly a specific div of A1.html when the back link in A2.html is pressed.

推荐答案

尽管您设置了 target << a> 元素的/code>属性设置为"_blank".如果您确实希望链接看起来正常工作,那么您需要做的是通过设置事件处理程序,然后在JavaScript中更改DOM来拦截对链接的点击.

You can't navigate within a Chrome App window (Content Security Policy), although you can navigate to an external browser if you set the target attribute of the <a> element to "_blank". What you have to do, if you really want links to appear to work normally, is intercept the click on the link by setting an event handler and then changing the DOM from within JavaScript.

如果您有HTML片段,则从JavaScript更改DOM的一种简单方法是使用 insertAdjacentHTML API(将Google用作文档).

One easy way to change the DOM from JavaScript if you have an HTML fragment is to use the insertAdjacentHTML API (Google it for documentation).

尽管这似乎很尴尬,甚至有局限性,但还是将Chrome应用程序视为应用程序而不是网页.毕竟,对于本机Mac OS X或Windows应用程序,您不会期望仅单击一个按钮就可以完全更改窗口中的UI,对吗?您希望该应用程序可以通过本机API做到这一点.与Chrome应用相同.

While this might seem awkward, even limiting, think of a Chrome App as an app, and not a web page. After all, with a native Mac OS X or Windows app, you wouldn't expect to entirely change the UI in a window by simply clicking on a button, right? You'd expect that the app would do that via the native API. Same the Chrome Apps.

或者,您可以在Chrome应用程序窗口中放置一个Web视图,然后该Web视图中的HTML便可以正常工作,因为那确实是一个"Web视图".

Alternatively, you can position a webview in the Chrome App window, and then HTML within the webview works normally, because that really is a "web view."

这篇关于如何在不创建新窗口的情况下导航到chrome应用程序中的不同页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆