我们在Windows应用程序中有一个特性,它可以打开web浏览器,导航到某些预配置的web站点,并使用数据库中的数据自动填充表单--这对用户来说是一个方便的特性。
现在,我们想要构建此功能的Asp.Net版本,以便在web应用程序中,用户单击一个链接/按钮,然后我们打开页面(使用重定向?使用JavaScript?)。然后,我们填写表单,以便用户可以查看数据并提交。
为此,我认为我们要么需要将javascript注入到加载外部窗口的浏览器框架中,要么需要能够与该窗口进行交互。
我们担心浏览器安全可能不允许这样做--它可能看起来像是某种欺骗攻击。做这件事的好方法是什么?
发布于 2012-08-21 05:26:36
如果在打开弹出窗口的网站和在弹出窗口中打开的网站之间的域、协议和端口不匹配,则您的代码将违反Same Origin Policy并被忽略或抛出异常。
下面是一个示例来演示:
<!doctype html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<script type="text/javascript">
openPopUp = function(href) {
var props = "width=500,height=500,menubar=no,toolbar=no,scrollbars=yes";
var win = window.open(href, href, props);
if (win == null) alert("Your popup blocker is ruining my demo.");
return win;
};
openMe = function(url){
href = (url=="")?document.location:url;
pu = openPopUp(href);
//This will be ignored silently if Same Origin Policy is violated
pu.onload = function() {
p = pu.document.createElement("p");
p.appendChild(pu.document.createTextNode("onload was here."));
pu.document.body.appendChild(p);
};
//This will throw an exception if Same Origin Policy is violated
setTimeout(function() {
p = pu.document.createElement("p");
p.appendChild(pu.document.createTextNode("setTimeout was here."));
pu.document.body.appendChild(p);
},3000);
return false;
}
</script>
<body>
<a href="" onclick="return openMe(this.href);">Self</a>
<a href="https://www.google.com/" onclick="return openMe(this.href);">Google</a>发布于 2012-08-21 04:33:15
您需要制作一个书签小程序。在您的asp.net页面中,创建一个链接,用户可以将该链接拖到其浏览器的书签中。用户单击指向您要填写的页面的链接。然后,他单击新创建的bookmarklet。
在纯javascript中,这是不可能的,这就是为什么你需要使用bookmarklet。
发布于 2012-08-21 05:01:41
场景:您有两个页面base.aspx和popup.aspx。在单击base.aspx上的链接时,您希望打开充满所需数据的popup.aspx。您可以同时控制base.aspx和popup.aspx
我认为你有几种方法可以做到这一点。
如果popup.aspx上所需的数据已加载到base.aspx上,则为
上的DB quering中获取数据
https://stackoverflow.com/questions/12044606
复制相似问题