精华内容
下载资源
问答
  • WKWebView跳转后的页面URL获取处理。直接贴代码。 DDBWebViewController.h // // DDBWebViewController.h // DDBIOS // // Created by liwx on 2018/3/14. // Copyright © 2018年 io.lwx. All rights reserved....

    WKWebView跳转后的页面URL获取处理。直接贴代码。
    DDBWebViewController.h

    //
    //  DDBWebViewController.h
    //  DDBIOS
    //
    //  Created by liwx on 2018/3/14.
    //  Copyright © 2018年 io.lwx. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface DDBWebViewController : DDBViewController
    @property (nonatomic, strong) NSString *urlString;
    @property (nonatomic, strong) NSString *titleName;//标题
    @end
    

    DDBWebViewController.m

    //
    //  DDBWebViewController.m
    //  DDBIOS
    //
    //  Created by liwx on 2018/3/14.
    //  Copyright © 2018年 io.lwx. All rights reserved.
    //
    
    #import "DDBWebViewController.h"
    #import <WebKit/WebKit.h>
    
    @interface DDBWebViewController ()<WKUIDelegate,WKNavigationDelegate>
    
    @property (weak, nonatomic)WKWebView *webView;
    
    @property (nonatomic, strong) NSString *originUrlString;//原始URL
    
    
    @end
    
    @implementation DDBWebViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view from its nib.
        WKWebView *web = [[WKWebView alloc]  initWithFrame:self.view.bounds];
        [self.view addSubview:web];
        [web mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.view);
        }];
        typeof(self) weakSelf = self;
        web.UIDelegate = self;
        web.navigationDelegate = weakSelf;
    
        self.webView = web;
        self.originUrlString = self.urlString.copy;
        if (self.urlString.length) {
            if (![self.urlString hasPrefix:@"http"]) {
                self.urlString = [NSString stringWithFormat:@"http://%@",self.urlString];
            }
            if ([self.urlString containsString:@"?"]) {
                if (![self.urlString containsString:@"fromApp=1"]) {
                    self.urlString = [self.urlString stringByAppendingString:@"&fromApp=1"];
                }
            } else {
                self.urlString = [self.urlString stringByAppendingString:@"?fromApp=1"];
            }
            NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.urlString]];
            [self.webView loadRequest:request];
        }
        [self initRightItem];
        [self initBackItem];
        [self.webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:NULL];
        //修改滚动速度
        for (UIView *v in self.webView.subviews) {
            if ([v isKindOfClass:NSClassFromString(@"WKScrollView")]) {
                UIScrollView *sv = (UIScrollView *)v;
                sv.decelerationRate = UIScrollViewDecelerationRateFast;
            }
        }
    }
    
    #pragma mark KVO的监听代理
    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
        //网页title
        if ([keyPath isEqualToString:@"title"]) {
            if (object == self.webView) {
                self.titleName = self.webView.title;
            } else {
                [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
            }
         } else {
            [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
         }
    }
    
    #pragma mark 移除观察者
    - (void)dealloc
    {
        [self.webView removeObserver:self forKeyPath:@"title"];
    }
    
    - (void)initBackItem {
        UIButton *backItem = [UIButton buttonWithType:UIButtonTypeCustom];
        UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"back_arrow_white"]];
        [backItem addSubview:img];
        backItem.frame = CGRectMake(0, 0, 60, 44);
        img.centerY = backItem.centerY;
        [backItem addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backItem];
    }
    
    
    - (void)backButtonAction {
    //    //返回
    //    if ([self.webView canGoBack]) {
    //        [self.webView goBack];
    //        return;
    //    }
        [self.navigationController popViewControllerAnimated:YES];
    
    }
    
    - (void)initRightItem {
        UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [rightButton setImage:[UIImage imageNamed:@"share-white"] forState:UIControlStateNormal];
        [rightButton setImage:[UIImage imageNamed:@"share-white"] forState:UIControlStateSelected];
        [rightButton setImage:[UIImage imageNamed:@"share-white"] forState:UIControlStateHighlighted];
        //rightButton.showsTouchWhenHighlighted = YES;
        [rightButton addTarget:self action:@selector(shareAction) forControlEvents:UIControlEventTouchUpInside];
        [self.navigationBar addSubview:rightButton];
        rightButton.frame = CGRectMake(SCREEN_WIDTH - 44, 0, 44, 44);
    }
    
    - (void)shareAction {
        //分享URL
        [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
            [self sharedToPlatform:platformType];
        }];
    }
    
    - (void)sharedToPlatform:(UMSocialPlatformType)type {
       //
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    // 类似 UIWebView的 -webView: shouldStartLoadWithRequest: navigationType:
    - (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation {
        NSLog(@"aaaa redirect....");
    }
    
    // 在收到响应后,决定是否跳转
    - (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler{
        NSLog(@"在收到响应后:%@",navigationResponse.response.URL.absoluteString);
        //允许跳转
        decisionHandler(WKNavigationResponsePolicyAllow);
        //不允许跳转
        //decisionHandler(WKNavigationResponsePolicyCancel);
    }
    
    // 在发送请求之前,决定是否跳转
    - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{
    
        NSString *url = navigationAction.request.URL.absoluteString;
        if (navigationAction.targetFrame.isMainFrame) {
            NSLog(@"target is main ... %@",url);
            if (navigationAction.sourceFrame.mainFrame) {
                NSLog(@"source is main...%@",url);
                //是原始url 放行
                if ([self.urlString isEqualToString:url]) {
                    decisionHandler(WKNavigationActionPolicyAllow);
                    NSLog(@"放行bbbbbbbbbbbbbbbbb...%@",url);
                    return;
                }
    
                //不是原始url
                if ([url isEqualToString:self.originUrlString]) {
                    //不是跳转后的url 放行
                    decisionHandler(WKNavigationActionPolicyAllow);
                    return;
                }
                //push后 修改后的url 放行
                if ([url containsString:@"fromApp=1"]) {
                    decisionHandler(WKNavigationActionPolicyAllow);
                    return;
                }
                //跳转
                NSLog(@"跳转aaaaaaaaaaaaaaaaaaaaaa...%@",url);
                decisionHandler(WKNavigationActionPolicyCancel);
                DDBWebViewController *pwVC = [[DDBWebViewController alloc] init];
                pwVC.urlString = url;
                [self.navigationController pushViewController:pwVC animated:YES];
                return;
            } else {
                NSLog(@"source is not main...%@",url);
            }
        } else {
            NSLog(@"target is not main ... %@",url);
        }
        decisionHandler(WKNavigationActionPolicyAllow);
        NSLog(@"在发送请求之前:%@",navigationAction.request.URL.absoluteString);
    }
    
    @end
    
    展开全文
  • 今天小编就为大家分享一篇vue 实现路由跳转时更改页面title,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
  • //路由发生变化修改页面title router.beforeEach((to, from, next) => { if (to.meta.title) { document.title = to.meta.title } next() }) //修改src/router/index.js文件 //每个path都添加meta: {} routes: [ ...

    //修改src/main.js文件
    //路由发生变化修改页面title
    router.beforeEach((to, from, next) => {
    if (to.meta.title) {
    document.title = to.meta.title
    }
    next()
    })

    //修改src/router/index.js文件
    //每个path都添加meta: {}
    routes: [
    {
    path: ‘/’,
    name: ‘index’,
    component: Index,
    meta: {
    title: ‘首页’
    }
    }
    ]
    })

    展开全文
  • vue-router跳转修改title

    2021-01-18 16:59:08
    this.$route.meta.title="我修改了meta"       this.$router.replace({           query: {      ...
          this.$route.meta.title="我修改了meta"
          this.$router.replace({
              query: {
                  temp: Date.now(),  //必有
                  id:this.$route.query.id,
              }
          });
    
    展开全文
  • 一、router文件夹下的index文件中给每个path添加meta:{}:export default new Router({routes: [{path: '/',name: 'index',component: index,meta: {title: 'title1'}},{path: '/studentInfo',name: 'studentInfo',...
  • 1.在路由数组设置里加meta对象 const routes = [ { path: '/workReport', component: WorkReport, meta: { title: '往期日报' } } ] const router = new VueRouter({ r...
  • 可实现跳转之后的title的改变,效果图: 方式2: 在每个路由的配置中,添加meta(源数据),添加title, { path:'/about', component:About, meta:{ title:'关于' } }, 然后调用: router..
  • 一、router文件夹下的index文件中给每个path添加meta:{}: export default new Router({ routes: [ { path: '/', name: 'index', component: index, ... title: 'title1' } }, { path: '/studentInfo',
  • 路由跳转代码如下,构造器导入路由router: constructor( aaa... private router: Router, bbb... ) { } toUrlPage(){ let params = { queryParams: { optType: 'apply' } }; setTimeout(() => { ...
  • //在路由跳转之前判断,除了首页以外,其他页面必须登录才能访问,异步问题 router.beforeEach((to, from, next) => { /* 路由发生变化修改页面title */ if (to.meta.title) { document.title = to.meta.title ...
  • vue-router 跳转页面的时候,修改页面的title为对应的路由 routes: [ { // 默认的首页 path: '/', name: 'Home', component: Home, meta: { index: 0, title: '首页' } }, ...
  • :如上图 先写路由 如:随便模拟一条二级路由 export default new Router({ routes: [ ... title:'用户列表' ... title:'列表信息' ...那么你会看见当你跳转页面时你的标题已经改变成你定义的了
  • vue路由跳转,页面title随之变化

    千次阅读 2019-04-08 14:38:06
    ## vue设置路由title,实现在vue路由发生变化的时候,相应的页面title随之变化 使用vue-wechat-title插件来解决 步骤: 1、在项目根目录下打开命令行通过 “npm install vue-wechat-title --save” 来安装插件。 2、...
  • 1.在router/index.js的每个路由中配置title   2.在项目中运行命令 npm install vue-wechat-title --save 安装插件(在 package.json文件的dependencies中可以看到已安装"vue-wechat-title": "^2.0.5") 3.在...
  • 一、通过路由钩子 1.每个路由添加一个meta [ { path:'/index', component:'Index', ... title: '首页' }, } ] 2.main.js文件加入钩子函数 new Vue({ el: '#app', router, components: { App ...
  • 文章目录(含效果图、演示代码)vue路由跳转不同页面的时候,自动更改页面title一、效果图演示:二、示例 · 重要代码:三、设置总结 · 类比 (含效果图、演示代码)vue路由跳转不同页面的时候,自动更改页面title...
  • 先看实现的效果视频: 一、要在router文件下的index.js文件下写 (每一个路由对象下配置meta)下面那我写的这个项目举例 const router = new Router({ ... meta: { title: "登录系统" } }, { path: '/ErrorRouter',
  • 此脚本配合这篇文章中的脚本使用,可以批量测试url的状态码、title跳转后的页面。 python3 ip:port格式转化成http、https格式文件 https://blog.csdn.net/doulicau/article/details/110704851 使用方法: ...
  • 首先交代背景,我在做一个网站的首页,首页上有很多图片,点击每个图片都跳转不同的链接,实现改变a标签父元素div的title属性以达到跳转不同的链接。写的时候从头写,所以记的时候从后面开始记。 JS部分:<scri
  • 一、router中增加title 二、在入口文件中进行判断

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 3,390
精华内容 1,356
关键字:

title跳转