How to hide image with src in wkwebview when loading html in ios? -
i'm using wkwebview loading html string, end of html string have few of ugly image links, want hide them.
the css use hide image, not works.
.article img[src* = "/smilies/"], .article img[src* = ".feedburner.com/~ff/"], .article img[src* = ".feedburner.com/~r/"], .article img[src* = ".feedblitz.com/"] { display: none; }
the sample html string feedburner src want hide :
<div> <a href="http://feeds.feedburner.com/~ff/venturebeat?a=h9eoocii8xi:sanx3-jfwnw:yil2auoc8za"><img src="http://feeds.feedburner.com/~ff/venturebeat?d=yil2auoc8za" border="0"></a> <a href="http://feeds.feedburner.com/~ff/venturebeat?a=h9eoocii8xi:sanx3-jfwnw:qj6idk7rits"><img src="http://feeds.feedburner.com/~ff/venturebeat?d=qj6idk7rits" border="0"></a> <a href="http://feeds.feedburner.com/~ff/venturebeat?a=h9eoocii8xi:sanx3-jfwnw:v_sglipbpwu"><img src="http://feeds.feedburner.com/~ff/venturebeat?i=h9eoocii8xi:sanx3-jfwnw:v_sglipbpwu" border="0"></a> <a href="http://feeds.feedburner.com/~ff/venturebeat?a=h9eoocii8xi:sanx3-jfwnw:i9og5soyxji"><img src="http://feeds.feedburner.com/~ff/venturebeat?d=i9og5soyxji" border="0"></a> <a href="http://feeds.feedburner.com/~ff/venturebeat?a=h9eoocii8xi:sanx3-jfwnw:d7dqb2pkexk"><img src="http://feeds.feedburner.com/~ff/venturebeat?i=h9eoocii8xi:sanx3-jfwnw:d7dqb2pkexk" border="0"></a> </div>
a quick , dirty way achieve using regular expressions. mind not ideal long html files not efficient real html parser.
// html posted nsstring *html = @"<div>\n\t<a href=\"http://feeds.feedburner.com/~ff/venturebeat?a=h9eoocii8xi:sanx3-jfwnw:yil2auoc8za\"><img src=\"http://feeds.feedburner.com/~ff/venturebeat?d=yil2auoc8za\" border=\"0\"></a> <a href=\"http://feeds.feedburner.com/~ff/venturebeat?a=h9eoocii8xi:sanx3-jfwnw:qj6idk7rits\"><img src=\"http://feeds.feedburner.com/~ff/venturebeat?d=qj6idk7rits\" border=\"0\"></a> <a href=\"http://feeds.feedburner.com/~ff/venturebeat?a=h9eoocii8xi:sanx3-jfwnw:v_sglipbpwu\"><img src=\"http://feeds.feedburner.com/~ff/venturebeat?i=h9eoocii8xi:sanx3-jfwnw:v_sglipbpwu\" border=\"0\"></a> <a href=\"http://feeds.feedburner.com/~ff/venturebeat?a=h9eoocii8xi:sanx3-jfwnw:i9og5soyxji\"><img src=\"http://feeds.feedburner.com/~ff/venturebeat?d=i9og5soyxji\" border=\"0\"></a> <a href=\"http://feeds.feedburner.com/~ff/venturebeat?a=h9eoocii8xi:sanx3-jfwnw:d7dqb2pkexk\"><img src=\"http://feeds.feedburner.com/~ff/venturebeat?i=h9eoocii8xi:sanx3-jfwnw:d7dqb2pkexk\" border=\"0\"></a>\n</div>"; // string containing source of images want delete nsstring *source = @"http://feeds.feedburner.com/~ff/"; // builds pattern matches tags of images want delete nsstring *pattern = [nsstring stringwithformat:@"<img src=\"%@.+?>", source]; // actual delete operation nsstring *cleanhtml = [html stringbyreplacingoccurrencesofstring:pattern withstring:@"" options:nsregularexpressionsearch range:nsmakerange(0, html.length)]; // want cleaned html (display it, ...) nslog(@"%@", cleanhtml);
Comments
Post a Comment