Actionlink opens a new window

Topics: Troubleshooting, Writing modules
Mar 1, 2012 at 7:18 PM

Hi!,

Is it possible to open a actionlink into a new browers window?, I got the following code, but its just opening a new tab in the current brower, kinda new to MVC and don´t realy get how pass throw a action and route value to a window.open in a regular javascript. Can someone point me in some direction?

 

@Html.ActionLink("GetDetalis", "Home", new { id = item.id }, new {target = "_blank"})

Developer
Mar 1, 2012 at 7:45 PM

Try asking Google first: http://google.com/?q=open+link+in+new+window+instead+of+tab I'm sure you'll find the answer ;)

Mar 2, 2012 at 12:52 PM

Lol, either you did something wrong, or unearthed a bug : your link links to 'http://google.com/?q=open' :P

Developer
Mar 2, 2012 at 1:05 PM
Edited Mar 2, 2012 at 1:06 PM

Whoops, seems like the + character doesn't work ;)

Long story short: just use '_new' instead of '_blank', and you're good to go (although I didn't actually test it; I got it from this site: http://www.mydigitallife.info/launch-and-open-links-in-new-window-or-tab-with-_blank-or-_new-as-target-in-html-and-their-difference/)

 

Mar 4, 2012 at 2:21 PM

well, _new acts just the same as _blank, just opens a new tab in the current browser, atleast it does in EI8. 

Developer
Mar 4, 2012 at 3:39 PM
Edited Mar 4, 2012 at 3:40 PM

I'm afraid you're out of luck: http://stackoverflow.com/questions/726761/javascript-open-in-a-new-window-not-tab

On the other hand, it's quite easy for a user to open a link in a new window by clicking the right buttons. Perhaps it even makes sense that a user should be the one deciding whether or not he wants to open a new page in a new indow or a new tab, instead of the page author?