I am developing web applications with c#, Aspnet 3.5, and Ajax 2.0.
Question - I run Application_1 in ie7. I would like to programmatically start running Application_2 from Application_1 in a new tab, no matter what the client settings are.
Until now I have been opening Application_2 in a new window from Application_1 using
ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID, "window.open('theurl',' width=800, height=500'); ", true);
I would like to do something similar to open a new tab.
Unfortunately there is no way to control whether the window opens in a new tab or new window. This is a user setting that can't be overridden in code.
Here is Microsoft's justification if you're interested.
"Regarding script, there is no "target='_tab'" feature or any direct access to tabs from script beyond what is available with multiple windows today. We are working on balancing the default behavior for whether a window opened from script opens as in a new frame or a tab."
IEBlog
You could inform your user that by holding ctrl+shift and clicking a link will open in a new tab.
As Paul already noted, this cannot be done via any script or code.
I think it's best to let your users decide (via their individual browser settings) how they want to open the new page - in a new window or in a new tab in the same window.
Related
I have a page with an iFrame on it.
On the page in the frame I have a button.
What I want is that if the user clicks on the button, another page is opened in it's own new window or tab. This functionality is to show the user a print friendly page.
How can I do this?
This is how I now try it:
Dim sb2 As New StringBuilder
sb2.Append("window.open('")
sb2.Append(sb.ToString)
sb2.Append("','NewPFWindow','menubar=1,toolbar=1,scrollbars=1,resizable=1,sandbox=""allow-same-origin allow-forms""')")
ClientScript.RegisterClientScriptBlock(Me.GetType, "si2", sb2.ToString, True)
sb holds the page like "mypage.aspx"
Another option is to resize the iFrame so the whole page will fit. Is that possible from code-behind?
rg.
Eric
Just provide a target that has not been named on your site yet, most people will use _blank for that
I.e.
link text
or if you want to tie that to another click-event somewhere else:
window.open('desiredLocationUrl....', "_blank");
Btw. it does not matter if that link is inside an iframe ;)
found it.
Apparently Chrome uses an undocumented feature.
The frame that is trying to put the new page in it's own window or tab, needs an extra option in the sandbox property called "Allow-popup'.
This is not documented on the w3schools.com website.
So by adding this to the sandbox property, you allow the browser to create new window/tab.
I'm having an issue with the OpenFileDialog class, where the OpenFileDialog window will open, but only behind every other application I have running in my OS. I've been hesitant to ask about this, but my search using many different keywords on Google, and searching other forums, has turned up nil. I'm using the following code in a button click event of the button on my web form I want the user to click on to open the file dialog:
Dim fd As New OpenFileDialog()
Dim strFileName As String = ""
fd.Title = "Open File Dialog"
fd.InitialDirectory = "C:\"
fd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
fd.FilterIndex = 2
fd.RestoreDirectory = True
If fd.ShowDialog = DialogResult.OK Then
strFileName = fd.FileName
End If
The dialog box opens - it just opens behind every other window...what am I missing here? Am I just going to have to do a funky workaround by minimizing everything when I call the OpenFileDialog class? All I need is for the window to show in front of the browser and every other window. Thanks in advance for your help!
openfiledialog has no place in a standard ASP.NET application. If you call ShowDialog on it, the dialog will open on the server computer (under what user session?) unbeknownst to user looking at the browser window on the client.
Use <input type="file" ... or FileUpload server control to let user select a file to be uploaded to the server.
I'm working in ASP.NET (2.0) and we have a page where a user is able to select and download a series of files as a zip. I got this to work without undo difficulty by using the DotNetZip library (which is probably not relevant to the problem, but included for completeness.)
After the user checks which files they want to download, the page does a postback, and in the button click event handler, I use the following code:
Response.Clear();
Response.BufferOutput = false; // false = stream immediately
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "filename=FileRequest.zip");
using (ZipFile zip = new ZipFile())
{
zip.AddFile(MapPath("/datafiles/fileToZip.pdf"), "");
zip.Save(Response.OutputStream);
}
Response.Close();
And this all seems to work great. The user clicks the button, a download window pops up, the user downloads the zip. All is good...
...until they decide they want to do something else on the page. The buttons in the form are no longer responsive. For instance, if I click the download button again, it does nothing. If I reload the page, I can repeat this behavior...it works once, then does nothing.
I'm not understanding why the browser doesn't send the new request. It's not "spinning" or otherwise acting busy. I thought that this might be a browser issue, but I've repeated it in both IE and Firefox, so it seems likely that it's something I'm not understanding. Strangely, it's only form submission elements that seem to be non-responsive. Javascript still works, and so do regular links.
So why is this happening, and how do I get around it?
The problem is likely down to you returning;
Response.ContentType = "application/zip";
Once this has been sent (along with the actual content), the browser would assume it has nothing left to do (I believe).
You probably should create a new window specifically for downloading the files by saving the file selection in a session parameter (or equivalent) and opening a popup window that has your download code in.
This will leave the parent page in a suitable state.
Content-disposition header seems to be a discouraged solution. But the same effect of ASP.NET forms not being responsive occurs if you use standard Redirect to a zip file.
I solved very similar problem (returning *.csv files by the server for download) using Tančev Saša's code in "Response.Redirect to new window" Q&A and it works great. Perhaps it might produce some popup warnings in some browsers, but I think this is how it's often done in download sites.
How can I open my Default.aspx page without Addressbar, Menubar & Statusbar?
Remember it's the user with an already-opened web browser that chooses to visit your website, effectively Default.aspx page, whether or not the browser is launched by you or a program while testing your website. So a bit of client-side/JavaScript "magic" is needed to modify or fake the desired result based on an already existing browser window...
Using JavaScript, you can launch a new window with those features turned off, and close the old window. For example, IE's window.open(..) args are specified here.
It provides an example
varCustomFeatures = 'titlebar=no, status=no,menubar=no,resizable=yes, scrollbars=no,toolbar=no,location=no,directories=no,left=0,top=0,height=';
window.open(windowURL, '_blank' , varCustomFeatures,true);
Details may vary between browser in which case you will likely need to employ browser detection.
You can't.
However, you can create a popup windows without the bars in Javascript using open method, like this:
open("MyPage.aspx", "MyWindow", "toolbar=no,status=no,menubar=no");
I'm using WatiN (Web Application Testing in .Net) to do integration testing on a Dynamics CRM 4.0 website.
CRM uses a lot of popup windows - eg clicking on a Contact in a list opens a new browser window with the Contact's details.
I want to test:
login to CRM (done)
go to the Contact list (done)
click on an Contact, thus trigger the popup (done)
test functionality within the Contact entity/form (can't do)
So I need to get hold of the popped up window.
How?
Thanks.
//after the click that opens the popup:
IE iepopup_1 = IE.AttachToIE(Find.ByUrl(theUrlOfThePopup));
//operate on iepopup_1
Syntax has changed slightly in newest version of WatiN (v2.0.20.1089), is now:
IE poppedUpBrowser = IE.AttachTo<IE>(Find.ByUrl("http://www.popped-up-site.co.uk/"));
Maybe searching for only part of the URL would solve it. This can be done using regular expressions:
System.Text.RegularExpressions.Regex popupHiddenRegEx = new System.Text.RegularExpressions.Regex("part_Of_URL");
IE poppedUpBrowser = IE.AttachTo<IE>(Find.ByUrl(popupHiddenRegEx));