Silverlight open uri链接被浏览器阻止
问题很简单,但很烦人。我有一个按钮,点击事件只是打开一个链接Silverlight open uri链接被浏览器阻止,silverlight,silverlight-4.0,Silverlight,Silverlight 4.0,问题很简单,但很烦人。我有一个按钮,点击事件只是打开一个链接 HtmlPage.Window.Navigate(uri, "_blank"); 但它一直被浏览器阻止。我找了很多。似乎每个人都在使用这种方法,但没有人提到新的选项卡/窗口被阻止。那我该怎么办 更新 问题解决了。似乎要导航到外部网页,应该使用HyperlinkButton。这不会被浏览器阻止 “要启用到其他网页的用户导航,您可以使用HyperlinkButton控件,将NavigateUri属性设置为外部资源,并将TargetNam
HtmlPage.Window.Navigate(uri, "_blank");
但它一直被浏览器阻止。我找了很多。似乎每个人都在使用这种方法,但没有人提到新的选项卡/窗口被阻止。那我该怎么办
更新
问题解决了。似乎要导航到外部网页,应该使用HyperlinkButton。这不会被浏览器阻止
“要启用到其他网页的用户导航,您可以使用HyperlinkButton控件,将NavigateUri属性设置为外部资源,并将TargetName属性设置为打开新的浏览器窗口。”--
浏览器也会阻止PS.HtmlPage.PopupWindow。在我看来,如果用户不手动禁用块,HtmlPage.Window.Navigate和HtmlPage.PopupWindow是无用的。您是否考虑过Silverlight 3和4中的
System.Windows.Browser.HtmlPage.PopupWindow(uri,“\u blank”,null)
除了最后一个空值,您还可以通过设置一系列选项。您可以使用System.Windows.Browser.HtmlPage.Window.Eval,如下所示:
HtmlPage.Window.Eval("mywindowopener('http://www.google.com'")
调用javascript函数“mywindowopener”并传递URL。然后在Javascript中:
function mywindowopener(uri) {
window.loginDialog = window.open(uri, "popupwindow",
"height=320,width=480,location=no,menubar=no,toolbar=no");
}
“HtmlPage.Window.Eval”将绕过弹出窗口阻止程序,而“HtmlPage.Window.Invoke(mywindowopener,url)”或“HtmlPage.PopupWindow”将不会绕过弹出窗口阻止程序。Silverlight代码:
public static void OpenWindow(string url, WindowTarget target = WindowTarget._blank)
{
// This will be blocked by the pop-up blocker in some browsers
// HtmlPage.Window.Navigate(new Uri(url), target.ToString());
// Workaround: use a HyperlinkButton, but do make sure for IE9, you need to have
// <meta http-equiv="x-ua-compatible" content="IE=8" />
// and for all browsers, in the Silverlight control:
// <param name="enableNavigation" value="true" />
// Also, it seems the workaround only works in a user-triggered event handler
//
// References:
// 1. http://stackoverflow.com/questions/186553/sending-a-mouse-click-to-a-button-in-silverlight-2
// 2. http://stackoverflow.com/questions/14678235/silverlight-hyperlinkbutton-not-working-at-all
HyperlinkButton hb = new HyperlinkButton()
{
NavigateUri = new Uri(url),
TargetName = target.ToString()
};
(new HyperlinkButtonAutomationPeer(hb) as IInvokeProvider).Invoke();
}
publicstaticvoidopenwindow(字符串url,WindowTarget=WindowTarget.\u blank)
{
//这将被某些浏览器中的弹出窗口阻止程序阻止
//导航(新Uri(url),target.ToString());
//解决方法:使用HyperlinkButton,但请确保对于IE9,您需要
//
//对于所有浏览器,在Silverlight控件中:
//
//此外,该解决方案似乎只适用于用户触发的事件处理程序
//
//参考资料:
// 1. http://stackoverflow.com/questions/186553/sending-a-mouse-click-to-a-button-in-silverlight-2
// 2. http://stackoverflow.com/questions/14678235/silverlight-hyperlinkbutton-not-working-at-all
HyperlinkButton hb=新的HyperlinkButton()
{
NavigateUri=新Uri(url),
TargetName=target.ToString()
};
(新的HyperlinkButtonAutomationPeer(hb)作为IInvokeProvider)。Invoke();
}
包含Siverlight控件的Html页面:
<!--
http://stackoverflow.com/tags/x-ua-compatible/info
X-UA-Compatible is a IE-specific header that can be used to tell modern IE versions to
use a specific IE engine to render the page. For example, you can make IE8 use IE7 mode
or tell IE to use the newest available rendering engine.
-->
<meta http-equiv="x-ua-compatible" content="IE=8" />
<!-- If we don't have the the above meta tag, Silverlight HyperlinkButton won't work in IE9
Some Security issue (Unathorized access exception)
TODO:
1. Check if IE10 has the same issue or not;
2. Test this in IE7 or IE6.
-->
是否因为存在弹出窗口阻止程序而被阻止?如果是这样的话,我很高兴你不能避开它。嗨@Erno,我不知道有什么特殊的弹出窗口拦截器。它只是普通的浏览器。我只是觉得这个任务应该很常见。如果你在HTML页面上添加一个超链接,在新的浏览器窗口中打开一个页面,这会被阻止吗?@Erno,我认为这不是问题所在。我正在开发的web应用程序上有各种各样的链接:)你启用Html桥了吗:谢谢。我在没有任何HtmlPopupIndowOptions的情况下尝试了它,但它也被阻止了。无论如何,问题是通过使用HyperlinkButton解决的,请参阅update.should工作,与HtmlPage.Window.Navigate不同,HtmlPage.PopupWindow只调用Window.open JavaScript,HtmlPage.PopupWindow禁用弹出阻止程序,请参阅源代码:NativeHost.Current.BrowserService.TogglePopupLocker(true);
<!--
http://stackoverflow.com/tags/x-ua-compatible/info
X-UA-Compatible is a IE-specific header that can be used to tell modern IE versions to
use a specific IE engine to render the page. For example, you can make IE8 use IE7 mode
or tell IE to use the newest available rendering engine.
-->
<meta http-equiv="x-ua-compatible" content="IE=8" />
<!-- If we don't have the the above meta tag, Silverlight HyperlinkButton won't work in IE9
Some Security issue (Unathorized access exception)
TODO:
1. Check if IE10 has the same issue or not;
2. Test this in IE7 or IE6.
-->