473,411 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

link/href that will not scroll to the top of the page

Jezternz
145 100+
Okay, simple problem, probrabable simple answer.
I have <a href="#" onclick="javascript">Click Me</a>
So basicly I want an anchor to do some javascript wen its clicked, my problem is, whenever this link is pressed, because of the hash(#) the page is scrolled to the top. How can I make a link do nothing in html (ie leave the page position where it is) without it scrolling to the top of the page.

Thanks. Josh
Apr 25 '08 #1
11 17914
drhowarddrfine
7,435 Expert 4TB
Just leave the href off, or remove the hash.
Apr 26 '08 #2
Jezternz
145 100+
wow that simpl, I probrably shud have tried that lol, thanks. I think i have to leave the href on or I get validation errors.

Edit yeh neitehr of those work for me as
href="" sends the user back to domain.com when the actual page is domain.com/?p=news
and the removal of the href is not xhtml complient
Apr 26 '08 #3
Markus
6,050 Expert 4TB
wow that simpl, I probrably shud have tried that lol, thanks. I think i have to leave the href on or I get validation errors.

Edit yeh neitehr of those work for me as
href="" sends the user back to domain.com when the actual page is domain.com/?p=news
and the removal of the href is not xhtml complient
Why not use like <span onclick=..> ? Or is that not valid?
Apr 26 '08 #4
Death Slaught
1,137 1GB
Or you could just do this:

[HTML]<a name="placeHolder">&nbsp;</a>

<br />

<a href="http://domain.com#placeHolder" onclick="insert JavaScript here">Text to click.</a>[/HTML]


Thanks, Death
Apr 26 '08 #5
gits
5,390 Expert Mod 4TB
here is one more possibility:

Expand|Select|Wrap|Line Numbers
  1. <a href="javascript:return false;" onclick="alert('test');">Click Me</a>
or setting this during the execution:
Expand|Select|Wrap|Line Numbers
  1. <a href="#" onclick="alert('test'); this.href='javascript:return false;';">Click Me</a>
  2.  
it just replaces the hash with a javascript action that just returns false :) whatever this will be good for ... but it avoids to search for an anchor to jump to ...

kind regards
Apr 26 '08 #6
drhowarddrfine
7,435 Expert 4TB
the removal of the href is not xhtml complient
It is not invalid.
Authors may also create an A element that specifies no anchors, i.e., that doesn't specify href, name, or id.
.
Apr 26 '08 #7
gits
5,390 Expert Mod 4TB
It is not invalid. .
then this should be the preferred solution, since it reduces the overhead of all the other suggestions :) ?

kind regards
Apr 26 '08 #8
Jezternz
145 100+
I think I will go with this one.
here is one more possibility:
[HTML]<a href="javascript:return false;" onclick="alert('test');">Click Me</a>[/HTML]
Thanks heaps guys, much apreciated.

Edit: Although this works properly I do get a javascript error message (if i click on the little error box thingo down the bottom of ie that says "return statement outside of function".. Any other ideas? :(
Apr 27 '08 #9
harshmaul
490 Expert 256MB
I think I will go with this one.


Thanks heaps guys, much apreciated.

Edit: Although this works properly I do get a javascript error message (if i click on the little error box thingo down the bottom of ie that says "return statement outside of function".. Any other ideas? :(
Expand|Select|Wrap|Line Numbers
  1. <a href="javascript:void" onClick="do some javascript magic">clcik here</a>
Apr 28 '08 #10
Jezternz
145 100+
Expand|Select|Wrap|Line Numbers
  1. <a href="javascript:void" onClick="do some javascript magic">clcik here</a>
again thanks but still error, it shows "syntax error" :(
You would think there would be a simple answer for this, but none that work correctly so far.

Edit: This doesnt give errors for some reason even using return
Expand|Select|Wrap|Line Numbers
  1. <a href="#" onclick="retun dothis()">link</a>
where I just added "return false;" on the end of the function dothis

I apologize for any time I have wasted, thanks heaps guys.
May 1 '08 #11
Chiva
1
Hey, don't know if still need it but here you have for future references:

Expand|Select|Wrap|Line Numbers
  1. <a href="javascript: void(0)">
Feb 14 '12 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: crhaynes | last post by:
I'm having trouble with my CSS. My links are black, my hover is orange and my active link is red. When I select a link it turns red but i does not retain that color when the selected page loads. ...
3
by: ningjun.wang | last post by:
Hello: My html file contains the following image link: <a href="some_url"><img src="MyImage.gif"></a> How can I use Javascript to find out the value of some_url for the given image name...
1
by: Carlo Marchesoni | last post by:
I have a very strange problem. Simply creating a Masterpage with nothing in it but the Content Area and then making a page that uses this masterpage and has a DataView Control, binds to a DataSet...
33
by: STILL LEARNING | last post by:
I'm not sure if this can even be done, but what prompts the question is my desire to be able to create an "Uber Link" script/code of some sort, such that even if the html page contains nothing but...
0
by: joy0032 | last post by:
I want to place a link on a wap page to download a zip file to the mobile device. The page would be accessed by the device user and on clicking on the link the zip file should be downloaded to the...
4
by: Link | last post by:
how do i scroll page when i get to a location ... something like : <body onLoad="sl()"> <script languge="javascript"> function sl(){ if (document.stopper.y>50) { window.scroll(0,100); }...
4
Death Slaught
by: Death Slaught | last post by:
im making a web site for a friend and i need a section of a-z links on a music page that have all the artist there that start with that letter but it wont open. heres the code to the music page. ...
38
by: ted | last post by:
I have an old link that was widely distributed. I would now like to put a link on that old page that will go to a new page without displaying anything.
0
by: swagatikasahoo | last post by:
how to display all lines if i will scroll the picturebox. hi, ok i m sending the code. ****************************************************** Private Sub PictureBox1_Paint(ByVal sender As Object,...
1
by: tariquetuku | last post by:
How to create a login and logout link in a php page which will affect the session variable? Any code available?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.