473,378 Members | 1,447 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,378 software developers and data experts.

Follow link, then execute a function

I need to execute a function after a link to a section within the same
document has been clicked and the navigation has occurred. When using
the onclick event handler the JS function is executed before the
navigation occurs. I can't tie it to a window.onload event since the
link only navigates within the already loaded document.

I'm not having any luck searching due to not knowing what keywords to
use. I looked at an explanation of bubbling vs capturing, but that
doesn't appear to be what I need.

--
Spartanicus
Nov 17 '06 #1
3 3159
Daz

Spartanicus wrote:
I need to execute a function after a link to a section within the same
document has been clicked and the navigation has occurred. When using
the onclick event handler the JS function is executed before the
navigation occurs. I can't tie it to a window.onload event since the
link only navigates within the already loaded document.

I'm not having any luck searching due to not knowing what keywords to
use. I looked at an explanation of bubbling vs capturing, but that
doesn't appear to be what I need.

--
Spartanicus
Enclose the function to be called within a function statement. For
example:

objectName.onclick = function(){ functionToBeCalled(); }

Nov 17 '06 #2
so you mean moving to a named section using hash?

<a
name="1"
href="#2"

onclick="javascript:document.location='#2';alert(' youve_reached_2');"
>
asdas
</a>

..
..
..
..
<a
id="2"
name="2"
href="#1"

onclick="javascript:document.location='#1';documen t.getElementById('1').onfocus
= function(){alert('youve_reached_1')};"
>
asdas
</a>

the first onclick uses two js statements so you can be sure the first
executes before the second.
the second onclick does the same but uses onfocus which might be more
predictable.

dont use onclick though right, and this is a dirty solution!

Nov 17 '06 #3
VK

Spartanicus wrote:
I need to execute a function after a link to a section within the same
document has been clicked and the navigation has occurred. When using
the onclick event handler the JS function is executed before the
navigation occurs.
Yes, this behavior is by design. As already suggested you can move the
navigation part to the script as well, just don't use the whole href
replacement on hash or IE before 6 may get dizzy or nasty of that :-)

Your links then could be like:

<a href="#anchor001" onclick="self.location.hash='anchor001';
myFunction(); return false">Anchor 001</a>

This way with script enabled "return false" will prevent the default
navigation but will execute the programmed one.

With script disabled you'll get just a regular anchor.

Nov 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Carl Gilbert | last post by:
Hi How can I use a link to both run a peice of script and link to another page? So far I have the following: ----------------------------------------------------------------------- <A...
7
by: BekTek | last post by:
When I build boost libs, I realized that there is static link at runtime.. What does that mean? I thought static linking is done at compile time. Am I wrong?
2
by: Joris Gillis | last post by:
Hi everyone, I have this nasty little problem to which I can't find a solution: Consider an anchor <a name="Top" id="Top">Top</a> How can I follow/execute this link from within javascript?...
8
by: Salvatore Sanfilippo | last post by:
Hello all, I've a very simple problem that appears to don't have a simple solution. I've a (dynamically generated) page with a number of external links. What I need is that if the user clicks...
6
by: jeet_sen | last post by:
Hi, I have generated a table and have attached a pop up to display at onmouseover event of each cell. For each cell the pop up will display cell specific detailed data. I have generated the pop...
6
by: Spartanicus | last post by:
I'd like to execute a function when a <link rel="next" href="foo.htm"> type element is used. Although the "onclick" handler is allowed on the element, presumably because the functionality of the...
7
by: Kurda Yon | last post by:
Hi everybody, I cannot understand the following thinks. The last line of the fillowing code produces a message about mistake (not a valid MySQL- Link resource): $link = mysql_connect(...
2
by: Peter Michaux | last post by:
Hi, Below is an example of a synthetic click in Firefox. The browser does not follow the link. Is that the just the way synthetic clicks work of am I doing something wrong? I know the synthetic...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.