//跨域框架实现浏览器

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

//开启跨域
import web.form.util
web.form.util.crossDomain() 

//创建web窗体
var wb = web.form( winform,0x40000/*_UIFLAG_THEME*/ ) 
wb.noScriptErr = true;

//自动启用禁用 前进、后退等按钮
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=utf-8" />
</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 = wbFrame.location;
	}
} 
wb.DocumentComplete=function( pDisp, url) {
	winform.text = wbFrame.document.title;	
	winform.text = wbFrame.location;
	
	ele = wb.getEle("txtUrl");
	if(ele){
		ele.value = wbFrame.location;
	}
}  

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

winform.show();  
win.loopMessage();