JavaScript獲取網(wǎng)頁信息總結(jié)JavaScript獲取當(dāng)前頁面URL膘掰、title等识埋,
thisHash = document.location.hash;
是獲取鏈接屬性中在井號“#”后面的分段。
thisURL = document.URL;thisHREF = document.location.href;
thisSLoc = self.location.href;thisDLoc = document.location;
thisTLoc = top.location.href;
thisPLoc = parent.document.location;
thisTHost = top.location.hostname;
thisHost = location.hostname;
thisTitle = document.title;
thisProtocol = document.location.protocol;
thisPort = document.location.port;
thisHash = document.location.hash;
thisSearch = document.location.search;
thisPathname = document.location.pathname;
thisHtml = document.documentElement.innerHTML;
thisBodyText = document.documentElement.innerText;
//獲取網(wǎng)頁內(nèi)容文字
thisBodyText = document.body.innerText;
//獲取網(wǎng)頁內(nèi)容文字
舉個(gè)例子
獲取所有
html:NSString *lJs = @"document.documentElement.innerHTML";
獲取網(wǎng)頁
title:NSString *lJs2 = @"document.title";
UIWebView *lWebView = [self getCurrentWebView];
NSString *lHtml1 = [lWebView stringByEvaluatingJavaScriptFromString:lJs];
NSString *lHtml2 = [lWebView stringByEvaluatingJavaScriptFromString:lJs2];
在實(shí)際用途中 在webView的代理中使用相恃,當(dāng)webView加載完成時(shí)獲取網(wǎng)頁信息保存成NSString拦耐,過濾文字信息杀糯,可以重新加載webView。