ios與js交互,獲取webview完整url,title,獲取元素并賦值跳轉

document:屬性

document.title//設置文檔標題等價于HTML的標簽

document.bgColor//設置頁面背景色

document.fgColor//設置前景色(文本顏色)

document.linkColor//未點擊過的鏈接顏色

document.alinkColor//激活鏈接(焦點在此鏈接上)的顏色

document.vlinkColor//已點擊過的鏈接顏色

document.URL//設置URL屬性從而在同一窗口打開另一網頁

document.fileCreatedDate//文件建立日期,只讀屬性

document.fileModifiedDate//文件修改日期,只讀屬性

document.fileSize//文件大小,只讀屬性

document.cookie//設置和讀出cookie

document.charset//設置字符集 簡體中文:gb2312

document:方法

document.write()//動態向頁面寫入內容

document_createElement_x_x(Tag)//創建一個html標簽對象

document.getElementByIdx_x_x(ID)//獲得指定ID值的對象

document.getElementsByName(Name)//獲得指定Name值的對象

document.body.a(oTag)

body:子對象

document.body//指定文檔主體的開始和結束等價于

document.body.bgColor//設置或獲取對象后面的背景顏色

document.body.link//未點擊過的鏈接顏色

document.body.alink//激活鏈接(焦點在此鏈接上)的顏色

document.body.vlink//已點擊過的鏈接顏色

document.body.text//文本色

document.body.innerText//設置...之間的文本

document.body.innerHTML//設置...之間的HTML代碼

document.body.topMargin//頁面上邊距

document.body.leftMargin//頁面左邊距

document.body.rightMargin//頁面右邊距

document.body.bottomMargin//頁面下邊距

document.body.background//背景圖片

document.body.a(oTag) //動態生成一個HTML對象

location:子對象

document.location.hash// #號后的部分

document.location.host// 域名+端口號

document.location.hostname// 域名

document.location.href// 完整URL

document.location.pathname// 目錄部分

document.location.port// 端口號

document.location.protocol// 網絡協議(http:)

document.location.search// ?號后的部分

常用對象事件:

documeny.location.reload()//刷新網頁

document.location.reload(URL)//打開新的網頁

document.location.assign(URL)//打開新的網頁

document.location.replace(URL)//打開新的網頁

selection-選區子對象

document.selection

//分享標題

self.titleStr = [self.webview stringByEvaluatingJavaScriptFromString:@"document.title"];

//分享內容

NSString *str =@"document.getElementById('metades').value";

self.countStr = [webView stringByEvaluatingJavaScriptFromString:str];

if(self.countStr.length >140) {

self.countStr = [self.countStr substringToIndex:140];

}

//分享圖片

NSString *str1 =@"document.getElementById('imgshare').src";

//NSString *str = @"document.getElementById('shareImage');";

NSString *pageSource1 = [webView stringByEvaluatingJavaScriptFromString:str1];

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:pageSource1]];

self.imageShar = [UIImage imageWithData:data];

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容