473,406 Members | 2,371 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,406 software developers and data experts.

Dynamically changing HREF

I have hyperlink, <a class='navbar'
href="http://my.calendars.net/colchestercamra/">Diary</a>, that points to a
calendar.

What I want to be able to do is jump to calendars.net/colchestercamra/#month,
where I use JavaScript to set up the month.

Could I use an 'onclick' to set up the properties of the <a> tag just before
it jumps? I can't use window.location, as this currently remains static
(using frames I'm afraid!).

Cheers, Rob.
Jul 23 '05 #1
4 6521
You can have a simply try of ONCLICK to c if the navigation process before
the onclick event being fired.

or try: <a href="javascript: your_own_navigate_function();">...</a>

--
www.vicdir.com
"Robert Atkinson" <ra*******@tbs-ltd.co.uk> ????
news:ee*************************@posting.google.co m...
I have hyperlink, <a class='navbar'
href="http://my.calendars.net/colchestercamra/">Diary</a>, that points to a calendar.

What I want to be able to do is jump to calendars.net/colchestercamra/#month, where I use JavaScript to set up the month.

Could I use an 'onclick' to set up the properties of the <a> tag just before it jumps? I can't use window.location, as this currently remains static
(using frames I'm afraid!).

Cheers, Rob.

Jul 23 '05 #2
Robert Atkinson wrote:
I have hyperlink, <a class='navbar'
href="http://my.calendars.net/colchestercamra/">Diary</a>, that
points to a calendar.

What I want to be able to do is jump to
calendars.net/colchestercamra/#month, where I use JavaScript to set
up the month.

Could I use an 'onclick' to set up the properties of the <a> tag just
before it jumps? I can't use window.location, as this currently
remains static (using frames I'm afraid!).


A - elements have two properties that can be used by an - onclick -
handler to set a fragment identifier on the URL that they are about to
navigate to' the - href - property and the - hash - property. And -
onclick - handler is executed as a mehtod of the A element so the -
this - keyword is a reference to that element. As a result a fragment
identifier may be appended to the URL in the - href - property with:-

this.href += '#month';

- or assigned to the - hash - property as:-

this.hash = '#month';
Using the - href - is only safe if you know that it will never have a
fragment identifier already. Using the - hash -property will replace any
existing (default?) fragment identifier.

So, with:-

var mnths = ['January', 'February', 'March', 'April','May','June',
'July', 'August', 'September', 'October','November',
'December'];

- defined globally, the A element:-

<a href="http://example.com/page.html"
onclick="this.hash = '#'+mnths[(new Date()).getMonth()];">
.... </a>

- would navigate to:-

http://example.com/page.html#July

- this month, and:-

http://example.com/page.html#August

- next month (at least when javascript is enabled in the browser.
Otherwise it would just use the raw - href - attribute (With any default
fragment identifier it may have.)).

The - onclick - handler must either not have a return value, or return -
true - as it does not want to cancel the navigation, having just
modified the URL that will be navigate to.

Richard.
Jul 23 '05 #3
Richard - thanks for the reply. This is exactly what I was after.

Rob.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #4
Richard Cornford wrote:
...
var mnths = ['January', 'February', 'March', 'April','May','June',
'July', 'August', 'September', 'October','November',
'December'];

- defined globally, the A element:-

<a href="http://example.com/page.html"
onclick="this.hash = '#'+mnths[(new Date()).getMonth()];">
... </a>
...

Very nice solution provided by Richard.
Combine it with the idea presented at the following page
and make it even better ;-)
http://cross-browser.com/toys/link_interception.html
Jul 23 '05 #5

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

Similar topics

2
by: Satish Kumar Chimakurthi | last post by:
Hi all, An external solver program is dynamically producing files with different names 0000001.dat, 0000002.dat, 0000003.dat etc.....at regular intervals. These files contain all numeric data....
2
by: wjbell | last post by:
I have a piece of javascript I need to modify. Right now it changes a stylesheet in the document between style.css and no_indent.css. These are in the head of my document: <link rel=stylesheet...
3
by: Billy | last post by:
Hello, I'm having a problem dynamically changing the color of a table background. I'm not sure exactly how to word this, but I'll give an example. I have a function called greentored(propname)...
1
by: Dennis Marks | last post by:
I have a page with 3 divisions overlaying each other. I dynamically change the visibility to switch between them. On the Mac version of IE 5.1 I am not able to activate the scroll bars after making...
2
by: John | last post by:
Hi Everyone, I have a question about dynamically changing the length of a varchar(n) field, in case the value I'm trying to insert is too big and will give a "truncated" error, but before the...
4
by: Dunc | last post by:
I've got a c# app, and in the HTML in front I have a <divtag around some navigation controls, and I want to dynamically change it's ID so the CSS kicks in and highlights the currently selected...
7
by: petethebloke | last post by:
Can anyone help? I have a client who has made a "dynamic interactive map" of our city using Dreamweaver. Each map file has hotspots that pop-up a div with a little image when the mouse goes over...
1
by: hellohi | last post by:
Hello Everyone, I wanted to change the existing variable names dynamically.( like www.aol.com ) in this site images and some text is changing dynamically. like wise i need javascrip to write ...
3
by: senthilkumarb | last post by:
Dynamically changing browser settings Browser have various settings like - cookies, cache, etc... How to check a browser whether cookies is Enabled OR Disabled in the client machine using...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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.