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

Forcing an A:active status on a link via javascirpt

Hello.
I'm trying to solve a problem related to JS and CSS.
I produced an HTML page with several links and buttuns.
I then created a CSS file in order to display a yellow background when
a link is clicked by users.

UL.menu1 LI A:active{
BACKGROUND: yellow; COLOR: black

Naturally, having acted on the A:active property, when a link is
clicked, all the others lose the yellow background.
The fact is that my page have to reload frequently. The effect I'd like
to obtain is that, when the page reloads, the link that was 'active'
before reloading continued to show the yellow background.
Having the chance of retrieving the link ID, I tried to force this
status using a simple js line

activeLinkID.click();

at the body onload event. The click was executed but the yellow
background did not appear.

Is there a way to force an 'active' status via JS on the link ?

I thank you in advance for any help.

Newcomsas

Jun 9 '06 #1
3 2196
MB
Having the chance of retrieving the link ID, I tried to force this
status using a simple js line

activeLinkID.click();

at the body onload event. The click was executed but the yellow
background did not appear.


I would try:

document.getElementById(activeLinkID).style.backgr oundColor = "#ffff00";

Jun 9 '06 #2
Well, this was effectly the first solution I thought of. The fact is
that my page have several links; if you set directly the backgorund, it
remains shown even when you click on another link (so when the 'active'
status is passed to another <A HREF tag).
I frankly don't know how to 'tell' the first link to de-activate its
background when another is clicked :-(

Newcomsas


MB ha scritto:
Having the chance of retrieving the link ID, I tried to force this
status using a simple js line

activeLinkID.click();

at the body onload event. The click was executed but the yellow
background did not appear.


I would try:

document.getElementById(activeLinkID).style.backgr oundColor = "#ffff00";


Jun 9 '06 #3
MB

"Newcomsas" <ne*******@hotmail.com> skrev i meddelandet
news:11**********************@y43g2000cwc.googlegr oups.com...
Well, this was effectly the first solution I thought of. The fact is
that my page have several links; if you set directly the backgorund, it
remains shown even when you click on another link (so when the 'active'
status is passed to another <A HREF tag).
I frankly don't know how to 'tell' the first link to de-activate its
background when another is clicked :-(

Newcomsas
If I understand you correctly, a click on any of those links doesn't cause
the page to reload, but rather some javascript function is called, is that
right? Because then you can store the ID of the link you set the background
color for, in a variable and start by resetting the background color for the
previously clicked link:

if (lastClickedID != "")
document.getElementById(lastClickedID).style.backg roundColor = "";
document.getElementById(activeLinkID).style.backgr oundColor = "#ffff00";
lastClickedID = activeLinkID;

Also put this somewhere in the head of your document:
lastClickedID = "";
Otherwise you will get an error when 'if (lastClickedID != "")' runs,
because it would not have been set yet.

That would make sure the link color is only yellow on the link you just
clicked and not on any other link. But this will only work as long as the
page is not reloaded.


MB ha scritto:
> Having the chance of retrieving the link ID, I tried to force this
> status using a simple js line
>
> activeLinkID.click();
>
> at the body onload event. The click was executed but the yellow
> background did not appear.


I would try:

document.getElementById(activeLinkID).style.backgr oundColor = "#ffff00";

Jun 9 '06 #4

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

Similar topics

3
by: William Park | last post by:
(Cross-posted because I use Mozilla Firefox, but I think it's also CSS issue.) Usually when I move mouse over a link, the URL is displayed at the bottom on "status line". On some website,...
36
by: Peter Brause | last post by:
Hello, my stylesheet shows different colors for visited, active and hovered links. It works fine in IE 6, but in Opera 7 the color for the active link (red background) is never shown. How to...
11
by: Wilhelm Kutting | last post by:
Hi i got a problem running the active tag i use in my stylesheet definition #menu li a:active{ color: #8B008B; } What didt't work out Using
4
by: Stephen Poley | last post by:
The issue of the focus pseudo-class came up a few weeks ago, and I finally got around to trying it out (better late than never ...) The recommended order given for the pseudo-classes is link,...
2
by: Kelly | last post by:
I have a subform that display requisition information. One of the fields in the subform is a combo box that shows who requested the requisition. The users can change who requested the requisition...
1
by: DaveF | last post by:
Is there a way to be able to check a url link to see if it is active or not? Example. I put urls to images in an Iframe on my site. If they change the url, It gives me an image not found error. I...
9
by: newcomsas | last post by:
Hello. I'm working on a problem related with CSS and javascript: I have got a link on a page and a stylesheet file that makes the background color change when users click on it. Is there...
8
by: salad | last post by:
I was wondering how you handle active/inactive elements in a combo box. Let's say you have a combo box to select an employee. Joe Blow has been selected for many record however Joe has left the...
0
by: shorti | last post by:
We are running DB2 UDB 8.1 fp 14 on AIX using archival logging and online backups. I was running some disaster tests and found my database restore was not restoring to the latest active log. ...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...

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.