- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
nativescript 中的 webview 是否有“导航”事件?
我已经在 Xamarin (c#) 中用
完成了Browser.Navigating += Myfunction
nativescript中有这样的事件吗?我想这样做,如果我点击网站范围之外的链接,那么我希望设备打开该 url 的网页,而不是在 webview 内部导航。
最佳答案
为此,您可以处理 WebView
loadStartedEvent
,并验证 URL 是否在您站点的范围内。如果不是,您可以为 webview 设置新的 URL,您将能够阻止用户进入不同的网页。我附上示例代码。
主页.xml
<Page xmlns:RL="nativescript-ripple" xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo">
<GridLayout>
<WebView src="https://www.google.bg/" id="wv" />
</GridLayout>
</Page>
主页.ts
import { EventData } from 'data/observable';
import { Page } from 'ui/page';
import { HelloWorldModel } from './main-view-model';
import {StackLayout} from "ui/layouts/stack-layout";
import {WebView, LoadEventData} from "ui/web-view"
// Event handler for Page "navigatingTo" event attached in main-page.xml
export function navigatingTo(args: EventData) {
let page = <Page>args.object;
var webview:WebView = <WebView> page.getViewById("wv");
webview.on(WebView.loadStartedEvent, function (args: LoadEventData) {
let message;
console.log("url "+args.url.substring(0, 21));
console.log("eventName "+args.eventName);
console.log("navigationType "+args.navigationType);
if(args.url.substring(0, 21) !== "https://www.google.bg/"){
(<WebView>args.object).url="https://www.google.bg/";
console.log("returns back");
}
});
}
希望对你有帮助
关于webview - 导航上的 Nativescript webview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40288201/
如何在 Nativescript + Angular 中实现 RadioButtons? 我试过 RadioButton 插件,但它在编译时出错。我在 stackoverflow 上看到一篇文章说要使
每当我单击 window 的 nativeScript sidekick 下载链接时,它都会将我重定向到主页。我在那里没有看到 nativescript 助手的任何下载链接。所以我寻找关于sideki
如何在 nativescript-angular 中的分段栏中添加图像图标。你能帮我解决这个问题吗
我正在寻找一个开源的 NS7 替代 nativescript 下拉菜单。有没有人有建议。我正在将我的应用程序移植到 NS7,但无法找到替代付费版本插件的插件。 最佳答案 我的解决方法是打开一个包含下拉
enter image description here如何在 android 中更改启动画面 (LaunchScreenTheme) 的状态栏图标颜色? 我尝试了下面的代码,但它不起作用。 #FFF
Nativescript 5 已发布,我正在尝试更新 tns 版本。目前它 tns --version 显示为 4.3.2。 我遵循了 https://docs.nativescript.org/re
我想将大小为 3000*4200 像素的 SD 卡中的图像调整为 250*250 大小的个人资料图片。我尝试了很多使用 android BitmapFactory 的方法,但没有任何效果。 有这个插件
我想在 NativeScript 的绝对布局中在屏幕底部放置一个元素。 我有这个代码: 我发现 Absolut
最近我在用 nativescript 编写一个应用程序,现在我遇到一个问题,我不知道如何保存用户的登录状态。比如用户第一次登录,以后就不需要登录了。那么我该如何实现呢? 最佳答案 我确实在我的应用程序
我正在尝试在我的 NativeScript 应用程序中创建具有动态行数和列数的表或数据网格。我有一些产品类别和这些类别中的一些产品。产品对其所属类别有一些规范。以下是图形卡类别产品的 JSON 示例:
我没能找到列表选择器的 NS+JS 工作示例,文档中的示例都没有 XML 示例。有人可以帮忙吗? 最佳答案 您需要做的是绑定(bind)一个 的 items属性到页面上的数组 bindingConte
我正在尝试更改 nativescript 中 progress 组件的高度,如下所示: 但是 height 属性没有效果。如何更改此组件的高度? 最佳答案 您可以使用 height 属性更改 Pr
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 2年前关闭。 Improve this qu
在 NativeScript 中,是否可以从 Nativescript 应用程序中启动另一个应用程序? 假设我在一个应用程序中有一个按钮,当按下它时,它会启动 Waze 导航应用程序,并带有一个位置的
你如何附加到文件而不是覆盖它? file-system module文档解释了如何写入文件: The following example writes some text to a file. It
对于NS项目,如何设置最低iOS版本。 我有IPHONEOS_DEPLOYMENT_TARGET = 8.0;在我的build.xcconfig文件中 但是在构建过程中,我收到未设置的消息。 在构建过
我想从 NativeScript 项目中的自定义组件公开一个方法。这是概念设置: 我的组件.xml ...UI markup... MyComponent.ts export function l
使用最新版本的 Nativescript,我根据文档创建了一个插件,并且在运行 tns plugin add ../nativescript-keychain 之后我收到消息 Successfully
NativeScript 中 DIV 的替代方法是什么? 如何使用内嵌内容的 block ? 最佳答案 在浏览器中,div 的行为由 display CSS 属性决定。 例如,默认为block和ver
目前有以下命令: tns cloud build android --accountId= 返回这一行:Invalid accountId index provided 您如何为您的帐户获得正确的 a
我是一名优秀的程序员,十分优秀!