473,837 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Jezternz
145 New Member
Okay, simple problem, probrabable simple answer.
I have <a href="#" onclick="javasc ript">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 18021
drhowarddrfine
7,435 Recognized Expert Expert
Just leave the href off, or remove the hash.
Apr 26 '08 #2
Jezternz
145 New Member
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 Recognized Expert Expert
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 Top Contributor
Or you could just do this:

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

<br />

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


Thanks, Death
Apr 26 '08 #5
gits
5,390 Recognized Expert Moderator Expert
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 Recognized Expert Expert
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 Recognized Expert Moderator Expert
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 New Member
I think I will go with this one.
here is one more possibility:
[HTML]<a href="javascrip t: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 Recognized Expert Contributor
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

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

Similar topics

4
20232
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. Is i possible to retain that color? My navigation that i'm trying to get this corrected on is server-side include
3
11631
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 "MyImage.gif"? I know how to get the image object with a given name (e.g.
1
1279
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 works ok. But as soon as I add: <link href="~/css/styles.css" rel="stylesheet" type="text/css" /> to the Masterpage (with or without ~ doesn't matter) gives: Microsoft JScript runtime error: Object required
33
2403
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 a background image -or- a background color -- in other words, the page has neither content nor placed images -- any click, ANYWHERE, will launch the URL in your browser. I realize I can make traditional text links and graphics links; what I'm...
0
2439
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 mobile device
4
2288
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); } </script>
4
2381
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. <html> <head> <title>Music Page</title> </head> <body bgcolor="black"> <font color="red"> <center> </center>
38
5094
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
1225
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, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint eGraphics = e.Graphics TryToCreateRec(eGraphics) PictureBox1.Refresh() End Sub Public Sub TryToCreateRec(ByVal eGraphics As Graphics) Dim blackPen As New Pen(Color.White,...
1
2034
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
9846
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
10583
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10638
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10280
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5679
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5859
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4481
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4056
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3128
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.