//跨域框架实现浏览器

import web.form;
import web.form.util
/*DSG{{*/
var winform = win.form(parent=...; bottom=479;text="用IFrame做的浏览器";border="resizable";right=735 )
winform.add(  )
/*}}*/

//开启跨域 
web.form.util.crossDomain() 
//创建web窗体
var wb = web.form( winform,0x40000/*_UIFLAG_THEME*/ ) 

//自动启用禁用　前进、后退等按钮
wb.CommandStateChange=function(cmd,enable) { 
    select(cmd) { 
        case 0x2/*_CSC_NAVIGATEBACK*/ { 
            wb.getEle("btnBack").disabled = !enable
        }
        case 0x1/*_CSC_NAVIGATEFORWARD*/ { 
            wb.getEle("btnForward").disabled = !enable
        }    
    }
}   

var html = /**
<html>
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body style="overflow:hide; margin:0px; "> 
<div id="navBar" style=" margin:5px;">  
        <label for="txtUrl">网址</label>
        <input type="text" name="txtUrl" id="txtUrl" value="http://www.baidu.com">
        <input id="btnGo" type="button" onClick="external.go(document.getElementById('txtUrl').value )"  value="打开" /> 
		<input id="btnRefresh" type="button" onClick="external.refresh()"  value="刷新" />
		<input id="btnBack" type="button" onClick="history.back()"  value="后退" />
        <input id="btnForward" type="button" onClick="history.forward()"  value="前进" />
</div> 
        <iframe name="xDomainFrame" src="http://www.baidu.com" frameborder="0" scrolling="yes" height="100%" width="100%" noresize="noresize">
        </iframe>
</body>
</html>
**/ 
string.save("/browser.html", html)
wb.go("/browser.html")
wb.wait();

wbFrame = wb.getWebForm("xDomainFrame") 

wb.BeforeNavigate2=function( pDisp, url, Flags, TargetFrameName, PostData, Headers, Cancel ) { 
	winform.text = "正在打开 " + url + " ......";
	ele = wb.getEle("txtUrl");
	if(ele){
		ele.value = url;
	}
} 
wb.DocumentComplete=function( pDisp, url) {
	winform.text = wbFrame.document.title;	
}  

wb.external={
	refresh = function(){
		wbFrame.refresh2()
	}
	go = function(...){
		wbFrame.go(...)
	} 
}

winform.show(); 

//进入消息循环
win.loopMessage();
