473,490 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Activating a link

I have a list of links using the following construct:

<a href='#artane' onclick='pos(1107,281)'>Artane</a>

The links offer additional functionality through JS. There are no actual
fragment IDs on the page, but the fragment coding allow the links to be
bookmarked. Via the window.onload event I check if a fragment ID is
present in the address, if so I need to activate the 'pos' function with
the appropriate arguments.

I'd like to loop through the links, if one has a href attribute value
that matches the window.location.hash value I'd like to activate that
link so as to avoid having to duplicate the 'pos' function's arguments
within the JS itself.

Am I going about this in an appropriate manner? If so I could use a
pointer to the JS feature that I need to activate an HTML link.

(As is probably obvious I know very little about JS)

--
Spartanicus
Oct 2 '06 #1
3 1599
Spartanicus wrote:
I have a list of links using the following construct:

<a href='#artane' onclick='pos(1107,281)'>Artane</a>

The links offer additional functionality through JS.
There are no actual fragment IDs on the page, but the
fragment coding allow the links to be bookmarked. Via
the window.onload event I check if a fragment ID is
present in the address, if so I need to activate the
'pos' function with the appropriate arguments.

I'd like to loop through the links, if one has a href
attribute value that matches the window.location.hash
value I'd like to activate that link so as to avoid
having to duplicate the 'pos' function's arguments
within the JS itself.
There is traditional (and W3C formaised) - document.links - collection
that includes all the links in a document. That could be iterated through
checking the - href - properties of the objects found. Those - href -
properties should be expected (but not required) to be normalised to
fully qualified URLs, so use - indexOf - (or similar) instead of straight
comparison.

The objects in the links collection may have (and will have is the HTML
attribute exists) an - onclick - property that is a reference to the
function that the browser generates from the HTML attribute. You may call
that function as a method of the object, in exactly the same way as the
browser would in response to an event. And as you are not using the event
object in the attribute code you will not even have to worry about faking
an event object.

For example, the onclick handler for the fist link on a page may be
called as:-

document.links[0].onclick();

This will indirectly execute your - pos - function with the arguments
used in the HTML attribute's call. However, it will _not_ navigate the
document, but as the fragment identifier is apparently already on the URL
at this point not having it added by navigation should make no
difference.

On the other hand if you wanted to call the - onclick - handler and then
navigate the document to the fragment identifier you could write a
modified URL to the - location - object, or assign the fragment
identifier to - location.hash -.
Am I going about this in an appropriate manner?
<snip>

Difficult to say without the mechanics of the 'why?'.

Richard.
Oct 3 '06 #2
"Richard Cornford" <Ri*****@litotes.demon.co.ukwrote:
>There is traditional (and W3C formaised) - document.links - collection
that includes all the links in a document. That could be iterated through
checking the - href - properties of the objects found. Those - href -
properties should be expected (but not required) to be normalised to
fully qualified URLs, so use - indexOf - (or similar) instead of straight
comparison.
[snip]

I managed to get it working using your information.
>Am I going about this in an appropriate manner?

Difficult to say without the mechanics of the 'why?'.
This is what the code was for:
http://homepage.ntlworld.ie/spartanicus/temp/

At this stage it is only a coding experiment which has some use for
myself hosted locally. It is not currently suitable for internet
deployment, nor does it offer much functionality likely to be useful to
others. I may later try to make it suitable and more useful for internet
deployment, the sub linking feature was the first issue towards that aim
that I wanted to tackle.

--
Spartanicus
Oct 4 '06 #3

Spartanicus wrote:
"Richard Cornford" <Ri*****@litotes.demon.co.ukwrote:
There is traditional (and W3C formaised) - document.links - collection
that includes all the links in a document. That could be iterated through
checking the - href - properties of the objects found. Those - href -
properties should be expected (but not required) to be normalised to
fully qualified URLs, so use - indexOf - (or similar) instead of straight
comparison.

[snip]

I managed to get it working using your information.
Am I going about this in an appropriate manner?
Difficult to say without the mechanics of the 'why?'.

This is what the code was for:
http://homepage.ntlworld.ie/spartanicus/temp/

At this stage it is only a coding experiment which has some use for
myself hosted locally. It is not currently suitable for internet
deployment, nor does it offer much functionality likely to be useful to
others. I may later try to make it suitable and more useful for internet
deployment, the sub linking feature was the first issue towards that aim
that I wanted to tackle.

--
Spartanicus
I really liked the page in the "example" link. I would think that the
site could be very popular to people interested in the city of Dublin
and for navigation thereof. Well designed and good navigation
techniques.

Info_Junkie

Oct 5 '06 #4

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

Similar topics

4
2074
by: Bill | last post by:
Is it possible to somehow activate a page containing a php script by sending an email to a mailbox on the server? I have a script that sends out notification emails to an individual. He wants to...
3
1577
by: Ruskin Hardie | last post by:
Ok, I am still playing with ASP and was wondering how to do this (it seemed simple). What I want is to have a hyperlink that when it's clicked on, will run a sub routine, instead of opening a web...
1
2651
by: Jeppe 1971 | last post by:
Hi Does anyone know of a way to load a HTML-page and examine the document without activating the code? I am trying to create a search-function in javascript. The idea is that the function...
6
3614
by: SF RVN | last post by:
Hmmmm.. a wee bit of a problem: Background default.htm has a left-aligned table serving as a 'navigation menu' and a right-aligned iFrame (named 'viewframe') serving as the 'target' for...
12
2043
by: magmike | last post by:
When users of my site submit articles to our database (http://www.netterweb.com/articles/) they almost always have http:// addresses within the text. They are pasting that text into a box which...
12
3757
by: ppcguy | last post by:
i've got a link that i give focus to via accesskey. <a href="blah" accesskey=p> in IE, that just gives it focus, but does not activate it. how do i activate the link. thx.
10
4045
by: Carlos Araya | last post by:
I have the following link on a web page <p class="menuitem"><a href="#" onclick="loadFragment('http://rivendellweb.net/fortress/home', 'index')" title="The Fortress Home">The Fortress...
0
7108
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
6967
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
7181
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...
1
6847
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
7352
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...
0
5445
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4875
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...
0
1383
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 ...
0
272
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...

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.