1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16// [Start use_load_interface_to_show_web_changes] 17import { webview } from '@kit.ArkWeb'; 18import { BusinessError } from '@kit.BasicServicesKit'; 19 20@Entry 21@Component 22struct WebComponent { 23 controller: webview.WebviewController = new webview.WebviewController(); 24 25 build() { 26 Column() { 27 Button('loadUrl') 28 .onClick(() => { 29 try { 30 // 点击按钮时,通过loadUrl,跳转到www.example1.com 31 this.controller.loadUrl('www.example1.com'); 32 } catch (error) { 33 console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`); 34 } 35 }) 36 // 组件创建时,加载www.example.com 37 Web({ src: 'www.example.com', controller: this.controller }); 38 } 39 } 40} 41// [End use_load_interface_to_show_web_changes]