locked
Open a new Window / Tab / Popup Window RRS feed

  • Question

  • 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.
    Saturday, October 3, 2009 5:23 PM

Answers

  • 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.

    Sunday, October 4, 2009 8:00 AM

All replies

  • 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.

    Saturday, October 3, 2009 7:23 PM
  • 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.
    Sunday, October 4, 2009 5:29 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.

    Sunday, October 4, 2009 8:00 AM
  • 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.
    Sunday, October 4, 2009 2:31 PM
  • 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.

    Thursday, October 22, 2009 2:35 AM
  •  Do i have to import some library to write the function in Silverlight 3.

    I can't get this code working

    HtmlPage.Window.Invoke("openNewWindow", "http://www.silverlight.net");

     

    Please reply asap

    Sunday, February 21, 2010 11:04 AM
  • You need to put the Javascript in the page like Rob Jacobs mentioned.
    Sunday, February 21, 2010 1:17 PM
  • Here is the complete thing which i need to do:

    I have a list of job ids on one page. i need to select one id and pass this to another page. The first page makes a couple of web service calls and the next page which needs to pop-up(in a new window) also does some specific work based on job-id(basically some web service calls depending on mouse clicks). So i need to one main page(aspx+xaml) and on selection of "job-id" a new window will be opened.

    As this new window  has some specific code, i need a seperate xaml file and aspx file for it. Again if the user selects a job-id with one page already open(except the job-id one i.e. mainpage) a new window should again open with the newly selected job-id details.

    So please tell me how to

    1) Open a new Window (basically an aspx page)

    2) Attach a xaml file to this aspx page.


     

    Monday, February 22, 2010 9:47 AM
  • Use a silverlight HyperlinkButton in your item template, set target to be _blank and pass through any data you need to the new window.

    I don't understand why people are suggesting using complicated javascript methods and the like, the HyperlinkButton works perfectly as the user clicks the link and launches a new window. If your application eventually becomes an OOB app then it will still work while relying on javascript will not.

    Monday, February 22, 2010 5:53 PM
  • Thanks Now can you help you me with attaching a xaml to an aspx file like the xxxxtestpage,aspx is bound to mainpage.xaml
    Tuesday, February 23, 2010 12:13 AM
  • Not knowing what you are doing (sounds like a strange architecture) Two options depending upon the silverlight content:

    1) create a new silverlight application in visual studio, it will ask you what web project you want to link to, select the exisitng project and ask for it to generate you an aspx test page, get the object code from there or enhance as you new page.

    This option would be useful if you want complete seperation from your two silverlight apps.

    2) use the same silverlight application, simply use the same object on your current aspx page on a new aspx page, use the initParams to tell your silverlight app what page it is comming from.

    RIA applications don't normally have full postbacks, to keep history and update the URL we normally use #, silverlight has built in support for this now. In ASP.NET we use updatepanels or AJAX enabled web services.

    Tuesday, February 23, 2010 12:46 AM
  • HyperlinkButton only responds to a mouse click event.  What if you need to navigate to a new page after a WCF service call has completed or some other event occurs in your application? Unfortunatly you can not simply fire the hyperlink button click event like you can in javascript (or at least no that I am aware of), hence the 'complicated' javascript methods...

    Sunday, March 7, 2010 2:05 PM
  • What is the scenario where you can't create a link in advance of the user clicking on it?

    Sunday, March 7, 2010 5:43 PM
  • Following your suggestion using the <HyperlinkButton> control, the link gets blocked when the IE8 popup blocker set to High (block all) . Do you have any ideas on how to open a link in a new window even with restrictive user settings such as this?

    Tuesday, May 11, 2010 6:02 PM