Form -> Submit
Takes you to view of the new entry.
How can I open a new tab that sends you to a new actionresult return File(document, mimeType); while still directing you on the main tab?
I'm at a loss, I cant open a new tab via ASP.NET Code, nor invoke two different actionresults.
Your problem should be solved on the client side, not only on the server. Maybe I misunderstood something, but if you want to open a new browser tab, you just need to place a <a href="#Html.Action("SomeAction")" target="_blank"> (Razor syntax) in your main tab.
You would need to do it client side. You have 2 options:
1) A shell page that has nothing except for the following javascript:
$(document).ready(function() {
window.open("#Model.DownloadUrl", "");
window.location.href = "#Model.RedirectUrl";
});
2) Modifying the view to check for a DownloadUrl via javascript and download it if available:
$(document).ready(function() {
if (#!string.IsNullOrEmpty(Model.DownloadUrl)) {
window.open("#Model.DownloadUrl", "");
}
});
In either case, there's no way to force the new window to be opened as a new tab. That's a user's browser setting. The javascript above opens a new tab in the version of Chrome and Firefox I have but not in IE.
Related
I have a page with a button that if clicked on it, a function is called that creates a pdf and it is opened in a new tab.
Now after clicking this button, I want to reload the current page then pdf file open in a new window.
How can I do this action without change request url?
I try to use below code but it change the url of new tab:
if (Request.UrlReferrer != null) Response.Redirect(Request.UrlReferrer.ToString());
I think you can use a simple JavaScript to reload current page completely
Have a look at this answer:
How to reload a page using JavaScript
You can use Request.UrlReferrer.ToString()
I have a View in Razor that when you have one set ViewBag, I want to open a url to print a report. I'm using Jquery code below, however, is opening in a new window and I want to always force to open a new tab, regardless of user configuration.
if (#ViewBag.Imprimir != null)
{
window.open('/Audiometria/Imprimir/' + #ViewBag.Imprimir, '_blank', 'toolbar=0,location=0,menubar=0');
}
It is important to note that whether or not a window.open() opens up a new tab or window depends on the browser implementation and user settings, and you can't force opening in a new tab.
Based on your window.open() parameters, most browsers will decide to open it in a new window, which makes sense since you have provided parameters to turn off certain UI elements (toolbar, location, menu bar etc.) that are usually present by default for all tabs, and usually it is not possible to turn off those elements only for a single tab.
If you omit the third parameter from your example it should open properly in a new tab in most new browsers, since you opening a plain new page without any specific UI settings for the browser, so there is a bigger chance that the browser will open it in a new tab.
window.open('/Audiometria/Imprimir/' + #ViewBag.Imprimir, '_blank');
I have a site and in my site when user click on a specific div then a new child window open . Suppose the user is standing at xyz.com/category , now if you user clicks on that div then parent windows goes to another url suppose google.com and a popup window will get open and there are some more navigation in popup windows . But every page that will open in popup has a button called Go Back To Site . I want that when user clicks on several links in popup and then click on Go Back To Site button then popup window get closed and parent window move back to xyz.com/category.
You can try PHP Superglobal array
$_SERVER['HTTP_REFERER']
If you can use javascript for this, there are simple functions such as:
window.history.back();
window.history.forward();
You can refer all of them in following link:
https://developer.mozilla.org/en/docs/DOM/Manipulating_the_browser_history
For Jquery:
$(document).ready(function() {
var referrer = document.referrer;
});
For C# :
WebBrowser1.Url = new Uri("http://maps.google.com");
- document.referrer does not work for IE
For this issue refer following code:
<script type="text/javascript" >
function redirect(url) {
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
var referLink = document.createElement('a');
referLink.href = url;
document.body.appendChild(referLink);
referLink.click();
} else {
location.href = url;
}
}
</script>
This code can also be refered over here
The way I'd do it is to pass the current URL as a parameter into your popup. So you would change your anchor link tags to this:
Click
So when your popup pops up, you just grab the value of prevPage and then when they click "Back to previous page", you just redirect to the value of prevPage.
Does anybody know how to open an URL in a new tab from C# code?
I have tried with
Response.Write("<script type='text/javascript'>window.location.href('../Documents/doc.pdf','_blank'); </script>");
Response.Write("<script type='text/javascript'>window.open('../Documents/doc.pdf','_blank'); </script>");
Response.Write("$('#pageContent_Send').click();");
with
$("#pageContent_Send").click(function () {
window.open("../Documents/doc.pdf");
return false;
});
and it did not work, using "window.open" I get an "Pop-up Blocker" browser warning.
There are a few options for opening a new tab that won't get blocked.
You can have it open the URL with an anchor click, like so click me
You can submit a form to a blank target, giving a similar result, but from a form. This is useful if you need to post, but can also be useful for get. Like so <form method="get" action="<your destination>" target="_blank"><button type="submit">Click Me</button></form>
You can use JS with window.open but it has to be tied to an active click event. I see in your original post that this got blocked, but if you're triggering it on a click event directly (i.e. not using a setTimeout or an async call or something else that delays the window opening) then this should work in all browsers. Since you're trying to "fake" it by forcing a click, the browser is going to block this every time unless you explicitly allow it.
<a href='www.xyz.com' target='_blank'>Click me to open me in new tab</a>
I am using MVC2 and VS2010.
We have created a web application but want to stop any browser re-visiting pages after the page has been left.
We want to do this so that someone who is using a public computer who then leaves can feel safe. We dont want the scenario that a following user can just use the back button to view the first uses pages.
I have tried [OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
This seems to work fine and I get a Web Page Expired. But if I press the browser back button again, the page will be displayed.
I have quite a similar situation myself in wanting to prevent a browser back situation and have researched a few different solutions. The first and worst being a Java script function which takes the user back to the page they were on if they click the back button in the browser. It hides the problem rather than solving it but thought id mention it. The code as follows:
<script type="text/javascript" language="javascript">
function disableBackButton() {
window.history.forward()
}
disableBackButton();
window.onload = disableBackButton();
window.onpageshow = function (evt) { if (evt.persisted) disableBackButton() }
window.onunload = function () { void (0) };
</script>
This works for Firefox, Chrome and IE ok. You can just put this in your master page.
Many people will tell you this is not the way to do things however as it intrudes on the well known browser behaviour etc etc
So my second suggestion is something I have seen here:
Disable browser cache for entire ASP.NET website
Which will not cache anything which is more inline with what you are wanting I think.
Another idea would be to pass a page or session token around and on actions check the token - if its invalid reroute to an error page. That would at least prevent a new user doing anything with the previous page.
Id be interested to know how you solved this, if you have solved it.