Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with <a> and javascript:void() 3

Status
Not open for further replies.

mcowen

Programmer
Oct 21, 2001
134
GB
Hi,

I'm building a table dynamically using the DOM and each row contains a link that I have built in such a way that it would be along the lines of...

Code:
<a href="javascript:void(1)" onclick="openFC(this)">Remortgage of 27 Dunroamin..</a>

The integer that is part of the void call is incremented for each row so that the links are not all identical. This makes sure that when clicking on one of the links in the table, just that link changes colour to indicate its been clicked. This is why I dont want to use

Code:
<a href="#" onclick="openFC(this)">Remortgage of 27 Dunroamin..</a>

Anyway, the problem I'm having is that the function called, openFC, doesnt navigate away to the page its supposed to. I can see that its called properly (by using alert) but the location.href call is ignored. I understand that this is what void does...it stops the navigation but is there a way around this? How can I create the link with a different href for each row?

Thanks

Matt
"Success is 10% inspiration, 90% last minute changes
 
Code:
<a href="javascript:openFC(this)">Remortgage of 27 Dunroamin..</a>


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
That doesnt answer my question. With your idea each href is going to be the same so i am no better off than using #.

Matt
"Success is 10% inspiration, 90% last minute changes
 
Than add a second, dummy, parameter to your openFC function, and change the link to this:
Code:
<a href="javascript:openFC(this,1)">Remortgage of 27 Dunroamin..</a>


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 

Or you could do this instead of using void():
Code:
<a href="javascript:[COLOR=red]//1[/color]" onclick="openFC(this)">Remortgage of 27 Dunroamin..</a>
But if you return false after the onclick, then the href will be ignored regardless (and is probably a better solution for you):
Code:
<a href="javascript:void(1)" onclick="openFC(this)[COLOR=red];return false[/color]">Remortgage of 27 Dunroamin..</a>
Cheers,
Jeff
 
Thats great. Thank you to you both. Due to the fact the link is added using DOM functions after the page has loaded I have had to use

Code:
  cell_link.onclick = new Function(function_call+";return false;");

which surprised me because it works fine in Mozilla and IE. Call me pessimistic but I didnt think it would be that forgiving.

Cheers,

Matt
"Success is 10% inspiration, 90% last minute changes
 
Actually, this isnt working as i would like. This fooled me into thinking the links were being registered as having been clicked (I had been testing and it had registered them prior to me implementing BabyJeffs idea above - daft I know). I'm beginning to think it cant be done.
Can anyone think of a way of setting a link as visited when the link has been added dynamically and the link invokes onclick?

thanks

Matt
"Success is 10% inspiration, 90% last minute changes
 
Change the style of the link to LOOK like it has been visited in the onclick function.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
How would this work when navigating away from the page and back again? When the page is reloaded the colour will revert.

Matt
"Success is 10% inspiration, 90% last minute changes
 
Unless you store the links visited in a cookie so you can reset them, it looks like you're out of luck. I wouldn't worry about it too much. I've learned to pretty much ignore whether the browser says a link has been visited or not, since using shift-click to open a link in a new window, using the back button, and things like that tend to mess with them anyway.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top