Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8519881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:22:36+00:00 2026-06-11T06:22:36+00:00

When the user clicks a link, I want to execute some code in a

  • 0

When the user clicks a link, I want to execute some code in a function inside the controller. But I want to prevent that the URL changes.

I tried the following possibilities

  1. Removed the href-attribute. Didn’t work, still changes the url to ‘/’

  2. Tried ng-click='deleteUser(user.id, $event)' and $event.preventDefault() in my deleteUser()-function. Didn’t work.

  3. What did work is a hack I’ve found on GitHub about an unintended reload.

This is how I do it now:

<a ng-click="deleteUser(user.id)" href="javascript:">Delete user</a>

Question

What is the’clean’ method to prevent a link from changing the URL?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:22:38+00:00Added an answer on June 11, 2026 at 6:22 am

    The real problem is in the a directive

    That’s right, every <a></a> element is actually an AngularJS directive.

    It seems to fix some issues with IE if you look the comments in the code.

    But everything for me is working great when I just removed the directive from the AngularJS core code.

    I was having the same problem as you did and tried all of the other solutions. The difference is that I had the problem only in IE.

    If you don’t want to play with building the AngularJS script from source, just search for htmlAnchorDirective in the angular.js file and remove/comment it out.

    I believe there is a bigger problem here which should be addressed in the AngularJS core, but I haven’t found it yet.

    UPDATE: This solution is most probably outdated now! You should try using the latest AngularJS version.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If the user clicks a link, I want to call a Javascript function if
Here is what I want to happen: The user should click a link/button that
Suppose, I want to have a link or a button that when user click
I have the following script that runs when a user clicks a link that
My app should render html, to answer when a user clicks ajax-link. My controller:
i want run a php code when a user click a link and change
I have a div that I hid when a user clicks the link and
I have controller with a page named list.html.erb when a user clicks a link
I'm trying to load some stuff using AJAX when a user clicks a link,
Use case: user clicks the link on a webpage - boom! load of files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.