gpt4 book ai didi

javascript - 无法使用深层链接获取网址

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:12:39 28 4
gpt4 key购买 nike

如果我在浏览器中点击这样的链接:

<a href="myapp_url_scheme://rest_of_address">Url Scheme Test</a>

我的应用程序已打开,但我无法获取 rest_of_address。每次都是undefined。我错过了什么?

我将 Ionic 2 与 Ionic Deeplinks 插件一起使用。这是我正在使用的代码:

app.component.ts

    import { Component, ViewChild } from '@angular/core';
import { App, Platform, AlertController } from 'ionic-angular';
import { StatusBar } from 'ionic-native';
import { TabsPage } from '../pages/tabs/tabs';
import { NavController, Nav } from 'ionic-angular';

import { LoginPage } from '../pages/login/login';
import { SignupPage } from '../pages/signup/signup';
import { AuthService } from '../pages/login/authservice';
import { HomePage } from '../pages/home/home';

import {Network} from 'ionic-native';
import {Deeplinks} from 'ionic-native';

@Component({
template: `<ion-nav [root]="rootPage"></ion-nav>`
})
export class MyApp {

rootPage: any = HomePage;
@ViewChild(Nav) navChild:Nav;

constructor(private platform: Platform, private alert :AlertController) {
platform.ready().then(() => {
StatusBar.styleDefault();

});

document.addEventListener('deviceready', function () {
var notificationOpenedCallback = function(jsonData) {
console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
if (jsonData.additionalData) {
if (jsonData.additionalData.myappurl)
this.rootPage = jsonData.additionalData.myappurl;
}

};

});
}

ngAfterViewInit() {
this.platform.ready().then(() => {
if((window.localStorage.getItem('email') === "undefined" || window.localStorage.getItem('email') === null) ||
(window.localStorage.getItem('password') === "undefined" || window.localStorage.getItem('password') === null)) {
this.rootPage = LoginPage;
} else {
Deeplinks.routeWithNavController(this.navChild, {
'/:urlAfterDomain': HomePage
});
}
});
}

}

home.ts

    import { Component } from '@angular/core';

import { NavController, NavParams } from 'ionic-angular';
import { AuthService } from '../login/authservice';
import {Deeplinks} from 'ionic-native';

@Component({
selector: 'page-home',
templateUrl: 'home.html'
})

export class HomePage {
urlAfterDomain: string;
constructor(public navCtrl: NavController, private _params: NavParams) {

this.navCtrl = navCtrl;
this.urlAfterDomain = _params.get('urlAfterDomain');
alert(this.urlAfterDomain);
if (this.urlAfterDomain == null || this.urlAfterDomain === "undefined") {
this.urlAfterDomain = "App";
}
else {
this.urlAfterDomain.replace( "myapp_url_scheme://", "");
}
this.urlAfterDomain = "https://myapp.com/" + this.urlAfterDomain;
alert(this.urlAfterDomain);
}

}

home.html

    <ion-header>
</ion-header>
<ion-content style="overflow: hidden;">
<iframe src={{urlAfterDomain}} height="100%" width="100%" frameborder="0"></iframe>
</ion-content>

最佳答案

我会推荐这样的东西

把你的网址改成这样:

<a href="myapp_url_scheme:///?restURL=rest_of_address">Url Scheme Test</a>

然后您可以从数据中获取 key “restURL”,它将开始工作。

关于javascript - 无法使用深层链接获取网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42191237/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com