zoukankan      html  css  js  c++  java
  • 设置WebView的UserAgent

    1、对于osx,设置WebView的UserAgent的方法

        WebView *webview = [[WebView alloc]initWithFrame:NSZeroRect];
        NSString *olderUserAgent = [webview stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
        NSString *newUserAgent = @"Appended Custom User Agent";
        NSString *userAgent = [NSString stringWithFormat:@"%@ %@",olderUserAgent,newUserAgent];
        [webview setCustomUserAgent:userAgent];

    2、对于osx,设置WKWebView的UserAgent的方法

    [webView setValue:userAgent forKey:@"customUserAgent"];//对于osx10.11以及以上使用该函数
    [webView setValue:userAgent forKey:@"applicationNameForUserAgent"];//对于osx10.10以及以下使用该函数,该函数是私有函数

    3、对于ios,设置WebView或WKWebView的UserAgent的方法

    NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:newUserAgent, @"UserAgent", nil];
    [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
  • 相关阅读:
    动手动脑
    选课1.0
    四则运算
    JAVA异常处理机制资料整理
    JAVA学习日报(快乐作业) 10.27
    JAVA学习日报(快乐作业) 10.20
    JAVA学习日报 9/30
    JAVA学习日报 9/28
    JAVA学习日报 9/27
    JAVA学习日报 9/26
  • 原文地址:https://www.cnblogs.com/yongbufangqi1988/p/7486562.html
Copyright © 2011-2022 走看看