Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2479
  • Last Modified:

How do I make asp:hyperlink control force to open a new page?

I have a asp:hyperlink control for which I am setting the NavigateURL value dynamically. I want to 'force' the link to ALWAYS open in a new window across ALL browsers. With Target="_blank" currently it sometimes opens in a tab and sometimes in a new window, but for this specific instance I want it to always open a new window.

<asp:hyperlink ID="PDF_Link" Target="_blank" NavigateUrl="~\random.pdf" runat="server"> <img height="24px" width="24px" src="Images/PDF_1.jpg" /> </asp:HyperLink>
0
lippert
Asked:
lippert
  • 6
  • 3
1 Solution
 
Hiran DesaiSolution ArchitectCommented:
Hello,
You can not control the behavior of the browser.Opening a new tab/window is functionality defined by the browser.


Say for example for the following code
<a href="#" target="_blank" >Click me!</a>
or for 
<a href="#" click="return function(){ window.open('http://google.com');return false; }">click me!</a>

Open in new window


Chrome Version 31.0.1650.63 m open up new window
firefox opens new tab
IE-11 opens up tab
IE-9 opens up new window


So that's browser developers who are making this thing variant.
hope this is helpful :)
0
 
lippertDeveloperAuthor Commented:
There's got to be a way to work around this. In all of the browsers you mentioned above, I have experienced instances where some pages are opened as a new window and others are opened in a new tab. I There is some content related attribute that causes the browsers to act differently in some situations. Just as one example, in Chrome, CTRL+t opens a new tab and CTRL+n opens a new window. I have trouble believing thay there's no way to do that from code... Think about it...

P.S. I don't give out points for telling me it can't be done.
0
 
Hiran DesaiSolution ArchitectCommented:
@lippert,
Expert Exchange is just not about earning points. It's more about experts are sharing their knowledge and are also here to learn something from the questioners.

Anyway, If there would be a way, I would like to know how that can be done so that It'll even help me to improve my knowledge.

BTW I'm here not be expert but I'll share my knowledge where ever I would like to.

Thank you.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
lippertDeveloperAuthor Commented:
@itWorked,

Thank you for your comment, but if there's one thing I've learned in 35 years of of software development, it's that "It can't be done!" is seldom true. It ususally means "I've never done it before, I don't know how to do it and I heard somewhere that it can't be done." I've never told my employer that it can't be done until I've invested enough time to know from personal experience that it can't.

Some of you might take this comment as a flame, but a few of you will take it as a challenge.
0
 
lippertDeveloperAuthor Commented:
OK, I answered enough of the question myself that I'm willing to give myself the points.

This solution may not work in all browsers, but here it is.

I wanted to insure that the new window I am opening ALWAYS opens in a new window, not a new tab. Assuming the browser is set to use tabs, you can force the window to open as a new window if you:
1> open the new window, use the javascript "window.open" method.
2> In the javascript, if you put anything in the attributes parameter that contradicts the attributes fo the current window, the browser will force the window to open in a new window.

Examples:

The statement window.open("viewPDF", "My Document", ""); will follow the browser's settings to determine if the window is opened in a new window or a new tab.

The statement window.open("viewPDF", "My Document", "location=0, left=170, top=100, scrollbars=0"); will force the browser to open the page in a new window.
0
 
lippertDeveloperAuthor Commented:
Just a general comment to everyone, please don't be so quick to say something can't be done unless you've invested your own time in trying to solve the same problem. Obviously some things that can't be done actually can be done.
0
 
Hiran DesaiSolution ArchitectCommented:
This was what my first comment. The solution can't handle behavior of the browser.
Anyway the solution is not working in IE...which does not support more then one argument in window.open .


But good thing is I have learned new thing is setting extra parameter for window properties can also override setting of User!
0
 
lippertDeveloperAuthor Commented:
This may not work across all browsers as I didn't have time to test it beyond the two on my desktop.
0
 
lippertDeveloperAuthor Commented:
The solution does work in IE for the 'average user' who has not changed the default IE "Tabs" setting of "Let Internet Explorer decide how pop-ups should open."
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now