本文整理匯總了Golang中github.com/nvsoft/cef.Browser.LoadURL方法的典型用法代碼示例。如果您正苦於以下問題:Golang Browser.LoadURL方法的具體用法?Golang Browser.LoadURL怎麽用?Golang Browser.LoadURL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/nvsoft/cef.Browser
的用法示例。
在下文中一共展示了Browser.LoadURL方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: doIt
func doIt(browser *cef.Browser) {
// 1.加載百度首頁
browser.LoadURL("http://www.baidu.com")
time.Sleep(5 * time.Second)
url := browser.GetURL()
fmt.Printf("Url=%v\n", url)
src := browser.GetSource()
ioutil.WriteFile("a.txt", []byte(src), 0644)
fmt.Printf("src=%v\n", len(src))
time.Sleep(200 * time.Second)
//js := `function() { return "1"; }();`
//browser.Eval(js)
// 執行Js
//browser.ExecuteJavaScript(`app.cefResult("a");`, "", 1)
result := browser.ExecuteJavaScriptWithResult(`(function() { cef.setResult("13"); })();`)
fmt.Printf("Eval Js. result=%v\n", result)
//browser.InjectJs("js/jquery.min.js")
// http://stackoverflow.com/questions/12605315/html5-getimagedata-without-canvas
// http://blog.csdn.net/hursing/article/details/12868109
//browser.InjectJs("js/imageutil.js")
//browser.InjectJs("js/html2canvas.js")
/*filename := browser.ExecuteJavaScriptWithResult(`
(function() {
var img = $("#lg img")[0];
var imageData = captureImage(img);
var filename = app.renderImage(imageData.data, imageData.width, imageData.height);
return filename;
})();`)
fmt.Printf("filename: %v\n", filename)
*/
/*
filename := browser.ExecuteJavaScriptWithResult(`
html2canvas(document.body, {
onrendered: function(canvas) {
var imageData = canvasToData(canvas);
var filename = app.renderImage(imageData.data, imageData.width, imageData.height);
app.cefResult(filename);
}
});
`)
fmt.Printf("filename: %v\n", filename)
*/
/*c := `var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
var img = $("#lg img")[0];
//var img = document.getElementById('tulip');
canvas.width = img.width;
canvas.height = img.height;
context.drawImage(img, 0, 0);//, img.width, img.height
var imageData = context.getImageData(0, 0, img.width, img.height);
//alert('3:' + img.width + '/' + img.height + '/' + imageData.data.length);
var txtFile = '';
//console.log('image.data.length=' + imageData.data.length);
var dataArray = new Array(imageData.data.length);
for (var i = 0; i < dataArray.length; i++) {
dataArray[i] = imageData.data[i];
}
var strImageData = dataArray.toString();
//console.log("strImageData=" + strImageData);
var filename = app.set_image_data(strImageData, img.width, img.height);
alert(filename);
//alert('4');`
//c := `var canvas = $("#lg img");var context = canvas[0].getContext("2d");alert(context);`
*/
// 獲取圖片
//browser.ExecuteJavaScript(c, "", 1)
// 發送進程消息
//browser.SendProcessMessageTest()
// 模擬點擊
code := `
function getOffset( el ) {
var _x = 0;
var _y = 0;
while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
_x += el.offsetLeft - el.scrollLeft;
_y += el.offsetTop - el.scrollTop;
// chrome/safari
//if ($.browser.webkit) {
el = el.parentNode;
//} else {
//.........這裏部分代碼省略.........