How can I remove/prevent a link from being linked to go for a page?
I want it to still be clickable but instead going to a page, just do nothing, stay on the same page.
For example, I have this:
Hyperlink
How can I disable the link of it? Presumably I have to write something else than "nothing"?
use
link
You can try like this:
<a href"#" onclick="doSomething(); return false;">Hyperlink</a>
The return false will prevent the href to go anywhere.
or simply
<a href='#'>Hyperlink</a>
# doesn't redirect but show cursor pointer.
something
if you want to change the cursor property.
add the css
.demo{
cursor:default;
}
Related
I wonder if someone can guide me on how to remove the url label that appears at the bottom of the page when you hover over an anchor (I wonder if it's even posible). I've googled a lot and didn't find any answers.
Suppose I have
<a href="www.somepage.com" title="The Page">Link< /a>
in the bottom of the page there will appear a tooltip/label showing "www.somepage.com".
Please see here for an example
Thanks in advance!
You can use either Javascript or JQuery.
For example, you can set to A attribute "href=#" and add an attribute url=www.somepage.com something like this:
Link
If you click over this nothing happen.
Now, you need to apply with javascript or JQuery click event. The next example is using JQuery and Javascript:
At the bottom of page's body:
<script>
$('#link').click(function() {
var url = $(this).attr('url');
window.location.href=url;
});
</script>
I have a link which opens a table on the same page if user clicks on the link. What I want to know is that is there another way to link on the same page rather than doing this:
[Open Grid]
This is because in the url it displays # at the end of the url so I want to know is there another way to link on the same page than href="#".
Thanks
Why even use an <a> tag if you are just binding an event handler to the element. Just use a <span> and style it. You can even give it cursor:pointer if you want that link feel/look
just return false in javascript and the link will not be followed when clicked, but you can still open your tables using js, as i suspect you do right now
as I understand you alread have some function binded to the click event of this link, right? if so you can just use href="javascript:void(0)", this way is much better, because in this case browser doesn't add a context menu items such as "Open link in new tab" or "Copy link address" to this link.
If you're using Javascript to detect when an element is clicked, you don't have to use tha anchor tag, or the href attribute.
You could do <a id="showGrid">Open Grid</a> and then something like $('a#showGrid').click(...); if using jQuery. To get the "link cursor" you can do a {cursor: pointer} in CSS. It'll look the same, but you won't get that # in the browser's address bar.
I need to have a piece of text, which looks like a link but actually only calls a handler when clicked. I've first wanted to use an Anchor for that but most website say to not use an anchor if it doesn't have a href, i.e. point to a URL.
So, what's the (semantically) correct way to do this in GWT?
Use a label and style it like an anchor
<g:Label ui:field="theLabelName" />
If you want to fire a history event, use the Hyperlink widget http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/ui/Hyperlink.html
If you just want to fire a random event.. not related to history, use a label like Jan mentioned.
new HTML("My Clickable Text");
Then add the click handler to the HTML
I have multiple defined as:
item A
and also I have a jquery script:
$(".item").click(function(){ itemclick(this); });
When a user positions the mouse between the items where the link is not active the itemclick() is executed without the link redirect.
How I can prevent this from happening?
Thanks
You don't show everything. It seems those links are inside other tags with class "item". So of course, if someone clicks outside a link but inside of that parent there won't be a "href" available to the function. There are several options, one would be to just not do anything if the clicked object is not a link <a ...>.
Give your links a class like:
<a class="link" href="col_c.php?id=1&field='A'" target="Frame3">item A</a>
and then use
$(".link").click(function(){ itemclick(this); });
I assume your .item is a div layer or a table row so it is also triggered around your link.
Simply execute the function only on the links themselves, not the whole parent (I expect your links are the children of something called .item).
$(".item a").click(function(){ itemclick(this); });
when you click on a link that goes to same page where the link is, how to keep the view of the page?
By default it goes to the top of the same page.
Regards
Javier
One way to do it is to add # at the end of the href attribute on the links pointing to the current page, either manually or via javascript. I don't think it's a nice way to do it, though...
If you really need this, you could also "disable" the navigation for links pointing to the current page, so that clicking on a link to the current page would have no action...
Something like that should work in jQuery :
$('a.current').click(function(event){
//cancel default click action
event.preventDefault();
}
assuming that the links pointing to the current page have the CSS class current
Can you be more specific? What do you mean with "view of the page"?
Here is a general description of anchors:
If you have a link Link then you need an element on the same page with id="someTarget". When you then click on the link, that element will be scrolled to the top of the element.
EDIT:
Ahm, you are talking about a JavaScript link. In that case you need to have the Javascript retur false so that the default action (namely following the link) is ignored:
<a href="#" ... onClick="myJqueryFunction(); return false;">