Skip to main content
Home Forums Silverlight Programming Programming with JavaScript Open a new Window / Tab / Popup Window
5 replies. Latest Post by SoulSolutions on October 22, 2009.
(0)
MarkMonster
Contributor
5220 points
1,046 Posts
10-03-2009 5:23 PM |
Hi all, I've been experimenting with a solution where I open a new Window/Tab on a click of a Silverlight Button (even better, open a popup window). But though we have a few things available for checking like HtmlPage.IsPopupWindowAllowed. One of the things I found out, is the usage of HtmlPage.Window.Navigate doesn't work in Google Chrome. I want to achieve a situation where I can open a new window (either tab / page / popup window) where I will load a Silverlight app as well. The opening is done from within Silverlight as well. I tried things like: HtmlPage.Window.Eval( string.Format( "window.open('{0}','mywindow','width=200,height=100,scrollbars=yes,toolbar=yes,location=yes'); ", uri)); Maybe someone has an idea I didn't try yet. Please let me know.
Rjacobs
Participant
920 points
155 Posts
10-03-2009 7:23 PM |
Create a javascript function using window.open in your silverlight host page then call that from your silverlight app passing the url. I know it sounds hokey, but it should be compatible with any browser.
10-04-2009 5:29 AM |
Thanks, but does this work with popup blockers? Most built-in popup blockers keep in mind, the fact that a click is user-initiated. Just like my first post I used Javascript using Eval, with the same problem, popups were blocked.
rjacobs
10-04-2009 8:00 AM |
I was focusing on the issue with HtmlPage.Window.Navigate not working at all with Google Chrome. I used the following code to test opening a new browser window:
Javascript in aspx page:
function openNewWindow(url) { window.open(url.toString(), "_blank", "", ""); }
Function in silverlight:
HtmlPage.Window.Invoke("openNewWindow", "http://www.silverlight.net");
This got further then just using the HtmlPage.Window.Navigate and did try to open a new window in Chrome. Yes, the popup blocker did stop it and asked me to allow the new window, but once I said yes and allowed the site to diplsay popups, I had no problems. I don't think you are going to get around the popup blocker prompt no matter what technology you are using.
10-04-2009 2:31 PM |
Thanks, but the thing that differs so much is comparing it to the experience when clicking a html hyperlink. We can specify a specific target (without javascript) works like a charm. If we want to do a popup, we can very easily do this using onclick on a hyperlink. That is working even while using a popup blocker. It's sad that we don't get the same experience like we already have using HTML.
soulsolu...
Member
27 points
10 Posts
10-22-2009 2:35 AM |
I've had great success using the <HyperlinkButton> control, setting the TargetName="_blank" and setting the NavigateUri property in code. If you know the address before they click the button (eg on control load or after loading some data) then this seems to work perfectly. I get a new window and no popup warnings.