【问题标题】:Get updated url from uiwebview从 uiwebview 获取更新的 url
【发布时间】:2013-02-15 21:25:01
【问题描述】:

我有一个 uiwebview 我在其中打开 http://google.com。然后我在谷歌搜索栏中输入一些东西并搜索一些东西。我想获取由于我在 google 上搜索而生成的更新后的 url。

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setUrlAddress:@"http://google.com.pk"];
    // Do any additional setup after loading the view from its nib.
    NSURL *url = [NSURL URLWithString:self.urlAddress];
    //URL Requst Object
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    //Load the request in the UIWebView.
    [self.webView setScalesPageToFit:YES];
    [self.webView loadRequest:requestObj];


}

- (void)webViewDidStartLoad:(UIWebView *)webView{
    [appDelegate showActivityView:self.view];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView{
    [appDelegate hideActivityView];
}

【问题讨论】:

  • 你需要使用 JaveScript 注入!NSString *stringURL = [webView stringByEvaluatingJavaScriptFromString:@"window.location.href"];

标签: iphone ios uiwebview uiwebviewdelegate


【解决方案1】:

试试这个

NSString *currentURL = [webView stringByEvaluatingJavaScriptFromString:@"window.location.href"];

希望对你有用

【讨论】:

  • 我已经检查过了,但它在调试模式下给出了 (_NSCFConstantString*)。但我发现那个字符串描述是空的。
  • @ShehzadAli 随时好友...享受编码:)
【解决方案2】:

以下是正确答案,但不适用于 Facebook 和 youtube

NSSTRing * currentURL = webView.request.URL.absoluteString;

如果有人知道更好的答案,请分享。

【讨论】:

    【解决方案3】:
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        NSString *urlAddress = [NSString stringWithFormat:@"http://www.google.com/pk];
    //Create a URL object.
        NSURL *url = [NSURL URLWithString:urlAddress];
    //URL Requst Object
       NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    //Load the request in the UIWebView.
       [webView loadRequest:requestObj];
    
    }
    

    【讨论】:

      【解决方案4】:

      试试这个委托方法:

      - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
      

      您可以获取请求并 nslog 该请求。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-01-30
        • 1970-01-01
        • 1970-01-01
        • 2019-03-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-08
        相关资源
        最近更新 更多