Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<a> link not working by clicking, only work by "Open link in new tab" command

Tags:

I meet this interesting situation:

<ul>     @foreach (var item in Model)     {       <li>         <a href="@Url.Action("Details", "Product", new { id = item.Id })" >@item.Name</a>       </li>     } </ul> 

When I click a link, nothing happen, product Details page does not open. But I do "Open link in new tab", then it opens. What can be it's reason?

like image 661
Jeyhun Rahimov Avatar asked Feb 24 '13 08:02

Jeyhun Rahimov


People also ask

Why is my a link not working?

Links may be broken for a variety of reasons, including the URL being mistyped, the webpage no longer being online, the page's URL having changed, or the linked page having restricted access (such as by being behind a password or firewall).

How do I make a clickable link open in a new tab?

How to Open Hyperlinks in a New Browser Tab or Window. The short answer is: just add a target="_blank" attribute to your links (anchor tags). Now when your visitors click that link, it will open in a new window or tab (depending on which web browser they are using and how they configured that browser).

How do I get links to open in a new tab without clicking?

Go to the link you want and press Ctrl+Enter to open in a new tab or just Enter to open in the same tab. You can use Shift+Enter to open it in a new window.

How can you force the browser to open a link in a new window or tab in HTML?

You just need an anchor ( <a> ) element with three important attributes: The href attribute set to the URL of the page you want to link to. The target attribute set to _blank , which tells the browser to open the link in a new tab/window, depending on the browser's settings.


2 Answers

You have some javascript code which is preventing the default action of the anchor tag to be executed. You could inspect the Network tab in FireBug or Chrome DevTools to see if some AJAX request is being made when you click on the link. You could try excluding javascript files until you find the one that is doing this.

like image 68
Darin Dimitrov Avatar answered Sep 19 '22 07:09

Darin Dimitrov


Maybe you prevented the redirection event of a tag with JavaScript.

For example:

$(document).on('click', 'a.thatTag', function (e) {    // ...    e.preventDefault(); }); 

.preventDefault() prevents redirection.

like image 33
Maq Avatar answered Sep 21 '22 07:09

Maq