|
1 | 1 | ---
|
2 | 2 | title: WebView
|
| 3 | +description: UI component for rendering web content. |
| 4 | +contributors: |
| 5 | + - rigor789 |
| 6 | + - Ombuweb |
3 | 7 | ---
|
4 | 8 |
|
5 |
| -`<WebView>` is a UI component that lets you show web content in your app. You can pull and show content from a URL or a local HTML file, or you can render static HTML content. |
| 9 | +`<WebView>` is a UI component for rendering web content. The content can be from a remote URL, a local file, or an inline string. |
6 | 10 |
|
7 | 11 | See also: [HtmlView](/ui/html-view).
|
8 | 12 |
|
9 |
| ---- |
10 |
| - |
11 | 13 | <DeviceFrame type="ios">
|
12 |
| -<img src="https://raw.githubusercontent.com/nativescript-vue/nativescript-vue-ui-tests/master/screenshots/ios-simulator103iPhone6/WebView.png"/> |
| 14 | +<img src="../screenshots/ios/WebView.png"/> |
13 | 15 | </DeviceFrame>
|
14 | 16 | <DeviceFrame type="android">
|
15 |
| -<img src="https://raw.githubusercontent.com/nativescript-vue/nativescript-vue-ui-tests/master/screenshots/android23/WebView.png" /> |
| 17 | +<img src="../screenshots/android/WebView.png"/> |
16 | 18 | </DeviceFrame>
|
17 | 19 |
|
18 |
| -<!-- /// flavor plain --> |
19 |
| - |
20 |
| -```xml |
21 |
| -<WebView row="1" loaded="onWebViewLoaded" id="myWebView" src="{{ webViewSrc }}" /> |
22 |
| -``` |
23 |
| - |
24 |
| -<!-- /// |
25 |
| -
|
26 |
| -/// flavor angular |
27 |
| -
|
28 |
| -```xml |
29 |
| -<WebView |
30 |
| - [src]="webViewSrc" |
31 |
| - (loadStarted)="onLoadStarted($event)" |
32 |
| - (loadFinished)="onLoadFinished($event)" |
33 |
| -> |
34 |
| -</WebView> |
35 |
| -``` |
36 |
| -
|
37 |
| -/// |
38 |
| -
|
39 |
| -/// flavor vue |
40 |
| -
|
41 |
| -```xml |
42 |
| -<WebView src="http://nativescript-vue.org/" /> |
43 |
| -
|
44 |
| -<WebView src="~/html/index.html" /> |
45 |
| -
|
46 |
| -<WebView src="<div><h1>Some static HTML</h1></div>" /> |
47 |
| -``` |
48 |
| -
|
49 |
| -/// |
50 |
| -
|
51 |
| -/// flavor svelte |
| 20 | +<<< @/../examples/src/ui/WebView/template.xml#example |
52 | 21 |
|
53 |
| -```xml |
54 |
| -<webView src="http://nativescript.org/" /> |
55 |
| -
|
56 |
| -<webView src="~/html/index.html" /> |
57 |
| -
|
58 |
| -<webView src="<div><h1>Some static HTML</h1></div>" /> |
59 |
| -``` |
60 |
| -
|
61 |
| -/// |
62 |
| -
|
63 |
| -/// flavor react |
64 |
| -
|
65 |
| -```tsx |
66 |
| -<webView src="http://nativescript.org/" /> |
67 |
| -
|
68 |
| -<webView src="~/html/index.html" /> |
69 |
| -
|
70 |
| -<webView src="<div><h1>Some static HTML</h1></div>" /> |
71 |
| -``` |
72 |
| -
|
73 |
| -/// --> |
74 |
| - |
75 |
| -::: tip Tip |
76 |
| -To be able to use gestures in WebView component on Android, we should first disabled the zoom control. To do that we could access the android property and with the help of setDisplayZoomControls to set this control to false. |
| 22 | +::: info Tip |
| 23 | +To be able to use gestures inside a WebView on Android, [disable zoom controls](#disableZoom). |
77 | 24 | :::
|
78 | 25 |
|
79 | 26 | ## Props
|
80 | 27 |
|
81 | 28 | ### src
|
82 | 29 |
|
83 |
| -```xml |
84 |
| -<WebView src="http://nativescript-vue.org/" /> |
| 30 | +```ts |
| 31 | +src: string |
| 32 | +``` |
85 | 33 |
|
86 |
| -<WebView src="~/html/index.html" /> |
| 34 | +The source to load in the WebView. The value can be a valid HTTP URL, a path to a local HTML file, or a HTML string. |
87 | 35 |
|
88 |
| -<WebView src="<div><h1>Some static HTML</h1></div>" /> |
89 |
| -``` |
| 36 | +**Example:** |
90 | 37 |
|
91 | 38 | ```ts
|
92 |
| -webView.src = 'http://nativescript-vue.org/' |
93 |
| -//or |
94 |
| -webView.src = '~/html/index.html' |
95 |
| -//or |
| 39 | +webView.src = 'https://nativescript.org/' |
| 40 | +webView.src = '~/assets/html/index.html' |
96 | 41 | webView.src = '<div><h1>Some static HTML</h1></div>'
|
97 | 42 | ```
|
98 | 43 |
|
99 |
| -Gets or sets the web content to be displayed. Valid values: |
100 |
| - |
101 |
| -- an absolute URL, |
102 |
| -- the path to a local HTML file, |
103 |
| -- or static HTML. |
104 |
| - |
105 |
| ---- |
| 44 | +::: warning Insecure URLs |
| 45 | +Depending on the software version of the device, insecure URLs may be blocked (`http://`), it's recommended to always use secure URLs (`https://`). |
| 46 | +::: |
106 | 47 |
|
107 | 48 | ### canGoBack
|
108 | 49 |
|
109 | 50 | ```ts
|
110 |
| -canGoBack: boolean = webView.canGoBack |
| 51 | +canGoBack: boolean |
111 | 52 | ```
|
112 | 53 |
|
113 | 54 | Gets a value indicating whether the WebView can navigate back.
|
114 | 55 |
|
115 |
| ---- |
116 |
| - |
117 | 56 | ### canGoForward
|
118 | 57 |
|
119 | 58 | ```ts
|
120 |
| -canGoForward: boolean = webView.canGoForward |
| 59 | +canGoForward: boolean |
121 | 60 | ```
|
122 | 61 |
|
123 | 62 | Gets a value indicating whether the WebView can navigate forward.
|
124 | 63 |
|
125 |
| ---- |
126 |
| - |
127 |
| -### disableZoom |
| 64 | +### disableZoom {#disableZoom} |
128 | 65 |
|
129 | 66 | ```ts
|
130 |
| -webView.disableZoom = true |
| 67 | +disableZoom: boolean |
131 | 68 | ```
|
132 | 69 |
|
133 |
| -Disable scrolling in the WebView. |
134 |
| - |
135 |
| ---- |
| 70 | +Disable zooming in the WebView. |
136 | 71 |
|
137 | 72 | ### iosAllowInlineMediaPlayback
|
138 | 73 |
|
139 |
| -```xml |
140 |
| -<WebView src="https://docs.nativescript.org/" iosAllowInlineMediaPlayback="true"/> |
141 |
| -``` |
142 |
| - |
143 | 74 | ```ts
|
144 |
| -webView.iosAllowInlineMediaPlayback = true |
| 75 | +iosAllowInlineMediaPlayback: boolean |
145 | 76 | ```
|
146 | 77 |
|
147 |
| -(`iOS only`) Enables inline media playback on iOS. By default, WebView forces iPhone into fullscreen media playback. |
| 78 | +Enables inline media playback on iOS. By default, WebView forces iPhone into fullscreen media playback. **iOS only.** |
148 | 79 |
|
149 |
| ---- |
| 80 | +### ...Inherited |
| 81 | + |
| 82 | +For additional inherited properties not shown, refer to the [API Reference](/api/class/WebView) |
150 | 83 |
|
151 | 84 | ## Methods
|
152 | 85 |
|
153 | 86 | ### stopLoading()
|
154 | 87 |
|
155 | 88 | ```ts
|
156 |
| -webView.stopLoading() |
| 89 | +stopLoading(): void |
157 | 90 | ```
|
158 | 91 |
|
159 | 92 | Stops loading the current content (if any).
|
160 | 93 |
|
161 |
| ---- |
162 |
| - |
163 | 94 | ### goBack()
|
164 | 95 |
|
165 | 96 | ```ts
|
166 |
| -webView.goBack() |
| 97 | +goBack(): void |
167 | 98 | ```
|
168 | 99 |
|
169 |
| -Navigates back. |
170 |
| - |
171 |
| ---- |
| 100 | +Navigates the WebView back. |
172 | 101 |
|
173 | 102 | ### goForward()
|
174 | 103 |
|
175 | 104 | ```ts
|
176 |
| -webView.goForward() |
| 105 | +goForward(): void |
177 | 106 | ```
|
178 | 107 |
|
179 |
| -Navigates forward. |
180 |
| - |
181 |
| ---- |
| 108 | +Navigates the WebView forward. |
182 | 109 |
|
183 | 110 | ### reload()
|
184 | 111 |
|
185 | 112 | ```ts
|
186 |
| -webView.reload() |
| 113 | +reload(): void |
187 | 114 | ```
|
188 | 115 |
|
189 | 116 | Reloads the current url.
|
190 | 117 |
|
191 |
| ---- |
192 |
| - |
193 |
| -### ...Inherited |
194 |
| - |
195 |
| -For additional inherited properties not shown, refer to the [API Reference](https://docs.nativescript.org/api-reference/classes/webview) |
196 |
| - |
197 | 118 | ## Events
|
198 | 119 |
|
199 | 120 | ### loadStarted
|
200 | 121 |
|
201 |
| -```xml |
202 |
| -<WebView src="https://docs.nativescript.org/" loadStarted="onLoadStarted"/> |
203 |
| -``` |
204 |
| - |
205 | 122 | ```ts
|
206 |
| -export function onLoadStarted(args) { |
207 |
| - const webView = args.object as WebView |
| 123 | +on('loadStarted', (args: EventData) => { |
| 124 | + const webView = arg.object as WebView |
208 | 125 |
|
209 |
| - console.log('Can go back? ', Object.keys(args)) |
210 |
| - console.log('Can go forward? ', webView.canGoForward) |
211 |
| -} |
| 126 | + console.log('WebView started loading', args.url) |
| 127 | +}) |
212 | 128 | ```
|
213 | 129 |
|
214 |
| -Emitted when the page has started loading in the `<WebView>`. The event data is of [LoadEventData](https://docs.nativescript.org/api-reference/interfaces/loadeventdata) type. |
| 130 | +Emitted when the page has started loading in the `<WebView>`. |
215 | 131 |
|
216 |
| ---- |
| 132 | +See [LoadEventData](/api/interface/LoadEventData). |
217 | 133 |
|
218 | 134 | ### loadFinished
|
219 | 135 |
|
220 |
| -```xml |
221 |
| -<WebView src="https://docs.nativescript.org/" loadFinished="onLoadFinished"/> |
222 |
| -``` |
223 |
| - |
224 | 136 | ```ts
|
225 |
| -export function onLoadFinished(args) { |
226 |
| - const webView = args.object as WebView |
| 137 | +on('loadFinished', (args: EventData) => { |
| 138 | + const webView = arg.object as WebView |
227 | 139 |
|
228 |
| - console.log('Can go back? ', Object.keys(args)) |
229 |
| - console.log('Can go forward? ', webView.canGoForward) |
230 |
| -} |
| 140 | + console.log('WebView finished loading', args.url) |
| 141 | +}) |
231 | 142 | ```
|
232 | 143 |
|
233 |
| -Emitted when the page has finished loading in the `<WebView>`. The event data is of [LoadEventData](https://docs.nativescript.org/api-reference/interfaces/loadeventdata) type. |
| 144 | +Emitted when the page has started loading in the `<WebView>`. |
234 | 145 |
|
235 |
| ---- |
| 146 | +See [LoadEventData](/api/interface/LoadEventData). |
236 | 147 |
|
237 | 148 | ## Native component
|
238 | 149 |
|
|
0 commit comments