读书人

C# 跳转有关问题(比较纠结) 快来

发布时间: 2012-09-25 09:55:59 作者: rapoo

C# 跳转问题(比较纠结) 大虾快来~
本人用C#写了一个C/S程序 要转换成ActiveX控件,要给JAVA端调用,以上是前提.
讲重点:C# C/S代码如下:
public void setToUrl(object url)
{
updateRegedit();
using (System.Web.UI.Page page = new System.Web.UI.Page())
{
page.Response.Write("<script language='javascript' type='text/javascript'>");
page.Response.Write("window.open(" + url + ",'全 屏','width=1366px,height=768px,directories=true,location=false,menubar=false,resizeable=false,scrollbars=yes,toolbar=false ');");
page.Response.Write("</script>");
}
}
以上代码不能被执行:原因不清楚。想达到的效果 用JS 打开新的页面,新打开的页面是要求全屏隐藏地址栏、菜单栏。
其中权限 我已经在 updateRegedit();方法中将网站地址 加入可信站点了,这样实现跨域可以隐藏地址栏.updateRegedit();
方法没有问题 我单独测试过
单独把
using (System.Web.UI.Page page = new System.Web.UI.Page())
{
page.Response.Write("<script language='javascript' type='text/javascript'>");
page.Response.Write("window.open(" + url + ",'全 屏','width=1366px,height=768px,directories=true,location=false,menubar=false,resizeable=false,scrollbars=yes,toolbar=false ');");
page.Response.Write("</script>");
}
这个方法领出来出来测试 发现就是执行不了,因为无法跟踪断点 所以都是 用排除法的
请教为什么这个方法执行不了。

前提以上代码实在WINfrom中的。
另外在winform中跳转 一下代码是成功的
public void setToUrl8(object url)
{
System.Diagnostics.Process.Start("http://www.baidu.com");
}
但是不能设置 打开后浏览器的样式等 ,让人纠结即不能隐藏地址栏,工具栏,菜单栏
有什么好方法请大侠们支几招

[解决办法]
page.Response.Write("window.open('" + url + "','全 屏','width=1366px,height=768px,directories=true,location=false,menubar=false,resizeable=false,scrollbars=yes,toolbar=false ');");
字符串两端要加引号,不然会被识别为变量,其他的暂时没发现什么
[解决办法]

C# code
 string url = "http://www.baidu.com";                       string script=string.Format(@"<script language='javascript' type='text/javascript'>                                        window.open('{0}','测试窗口','width=1366px,height=768px,directories=true,location=false,menubar=false,resizeable=false,scrollbars=yes,toolbar=false ');                                        </script>",url);            this.RegisterClientScriptBlock("Awoke", script);
[解决办法]
Sorry,貌似看错了,是在窗体中,通过测试找到了一种方法,如下可以在窗体中打开可定义大小的新网页窗口,说白了,就是通过WebBrowser 调用触发页面中的事件并调用JS方法
可以试试看

C# code
string url = "http://www.baidu.com";                string script = @"<script language='javascript' type='text/javascript'>                                        function openUrl(url){                                        window.open(url,'测试窗口','width=400px,height=400px,directories=true,location=false,menubar=false,resizeable=false,scrollbars=yes,toolbar=false ');                                        }</script>";                WebBrowser wb = new WebBrowser();                //wb.DocumentStream=                wb.DocumentText = @"<html> <head>" + script + "</head><body><a id='a_open' onclick='javascript:openUrl(\"" + url + "\");'</body></html>";                wb.DocumentCompleted+=(o,args)=>{                    HtmlDocument hDoc = wb.Document;                    HtmlElement hEle = hDoc.GetElementById("a_open");                    hEle.InvokeMember("click");                }; 


[解决办法]
简化一下,直接调用Document中的脚本

C# code
 string url = "http://www.baidu.com";                string script = @"<script language='javascript' type='text/javascript'>                                        function openUrl(url){                                        window.open(url,'测试窗口','width=400px,height=400px,directories=true,location=false,menubar=false,resizeable=false,scrollbars=yes,toolbar=false ');                                        }</script>";//定义脚本                WebBrowser wb = new WebBrowser();                wb.DocumentText = @"<html> <head>" + script + "</head><body></body></html>";//定义WebBrowser中的DOM文档                wb.DocumentCompleted+=(o,args)=>{                    wb.Document.InvokeScript("openUrl",new object[]{url});//执行脚本函数                }; 

读书人网 >C#

热点推荐