IOS native How to get the title, image, etc. of the Web interface

Source: Internet
Author: User

Reprint address:http://blog.csdn.net/justinjing0612/article/details/34127597

The hybrid development model has been popular in recent years, with some interaction between the native and HTML interfaces, or the invocation of methods.

Share hot I want to also say that the big Department app mimics a model. Today we are talking about a detail of sharing.

After we browse friends Circle of friends, if want to share to our friend circle, then we need to know WebView title and image, question, how do we know?

Sharing interface

Before I did not touch the time feel good magic ah, strong, ah, this also can, but recently inadvertently found very simple, is a sentence two words of the question.

No more concrete nonsense. Just look at the code first.

[HTML]View Plaincopy
    1. Self.title = [_webview stringbyevaluatingjavascriptfromstring:@ "Document.title"];
    2. NSLog (@ "title===%@", self.title);
    3. NSString *articleimageurl = [_webview stringbyevaluatingjavascriptfromstring:@ "DOCUMENT.IMAGES[0].SRC"];
    4. NSLog (@ "imageurl===%@", Articleimageurl);

Check out our output at the console:

[HTML]View Plaincopy
    1. 2014-06-24 19:31:19.182 demoapp[734:60b] title=== Baidu a bit
    2. 2014-06-24 19:31:19.183 demoapp[734:60b] imageurl===http://m.baidu.com/static/index/logo_index2.png

Haha, it's done. It's so simple.

Here are some of the similar features:

1. Get all the HTML for the Web interface:

[HTML]View Plaincopy
    1. NSString *lJs = [WebView stringbyevaluatingjavascriptfromstring:@ "Document.documentElement.innerHTML"];


2. Remove a property:

[HTML]View Plaincopy
    1. [WebView stringbyevaluatingjavascriptfromstring:[nsstring stringwithformat:@ "Document.images[%d].removeattribute ("width") ", I]];


3. Get the URL of the current page:

[HTML]View Plaincopy
      1. NSString *currenturl = [WebView stringbyevaluatingjavascriptfromstring:@ "Document.location.href"];

IOS native How to get the title, image, etc. of the Web interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.