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
- Self.title = [_webview stringbyevaluatingjavascriptfromstring:@ "Document.title"];
- NSLog (@ "title===%@", self.title);
- NSString *articleimageurl = [_webview stringbyevaluatingjavascriptfromstring:@ "DOCUMENT.IMAGES[0].SRC"];
- NSLog (@ "imageurl===%@", Articleimageurl);
Check out our output at the console:
[HTML]View Plaincopy
- 2014-06-24 19:31:19.182 demoapp[734:60b] title=== Baidu a bit
- 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
- NSString *lJs = [WebView stringbyevaluatingjavascriptfromstring:@ "Document.documentElement.innerHTML"];
2. Remove a property:
[HTML]View Plaincopy
- [WebView stringbyevaluatingjavascriptfromstring:[nsstring stringwithformat:@ "Document.images[%d].removeattribute ("width") ", I]];
3. Get the URL of the current page:
[HTML]View Plaincopy
- NSString *currenturl = [WebView stringbyevaluatingjavascriptfromstring:@ "Document.location.href"];
IOS native How to get the title, image, etc. of the Web interface