Current location: Hot Scripts Forums » General Web Coding » JavaScript » Link Problem With FireFox


Link Problem With FireFox

Reply
  #1 (permalink)  
Old 10-11-08, 09:42 AM
SmartzKool SmartzKool is offline
New Member
 
Join Date: Oct 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Link Problem With FireFox

Hello guys,

I am having a link problem with firefox. I am trying to link the full td with a url. It is working fine with IE but it doesn't work in Firefox. I am using the following code -

javascript Code:
  1. <td valign="top" class="style4">
  2. <a href="page.htm" style="display:block; cursor:pointer; text-decoration:none;">
  3. <script type="text/javascript">
  4.  
  5. var delay = 4000; //set delay between message change (in miliseconds)
  6. var maxsteps=30; // number of steps to take to change from start color to endcolor
  7. var stepdelay=40; // time in miliseconds of a single step
  8. //**Note: maxsteps*stepdelay will be total time in miliseconds of fading effect
  9. var startcolor= new Array(255,255,255); // start color (red, green, blue)
  10. var endcolor=new Array(0,0,0); // end color (red, green, blue)
  11.  
  12. var fcontent=new Array();
  13. begintag='<div style="font: normal 10px Arial; padding: 5px;">'; //set opening tag, such as font declarations
  14. fcontent[0]="Text sentence 1";
  15. fcontent[1]="Text sentence 2";
  16. fcontent[2]="Text sentence 3";
  17. fcontent[3]="Text sentence 4";
  18. fcontent[4]="Text sentence 5";
  19. closetag='</div>';
  20.  
  21. var fwidth='99%'; //set scroller width
  22. var fheight='68px'; //set scroller height
  23.  
  24. var fadelinks=1//should links inside scroller content also fade like text? 0 for no, 1 for yes.
  25.  
  26. ///No need to edit below this line/////////////////
  27.  
  28.  
  29. var ie4=document.all&&!document.getElementById;
  30. var DOM2=document.getElementById;
  31. var faderdelay=0;
  32. var index=0;
  33.  
  34.  
  35. /*Rafael Raposo edited function*/
  36. //function to change content
  37. function changecontent(){
  38.   if (index>=fcontent.length)
  39.     index=0
  40.   if (DOM2){
  41.     document.getElementById("fscroller").style.color="rgb("+startcolor[0]+", "+startcolor[1]+", "+startcolor[2]+")"
  42.     document.getElementById("fscroller").innerHTML=begintag+fcontent[index]+closetag
  43.     if (fadelinks)
  44.       linkcolorchange(1);
  45.     colorfade(1, 15);
  46.   }
  47.   else if (ie4)
  48.     document.all.fscroller.innerHTML=begintag+fcontent[index]+closetag;
  49.   index++
  50. }
  51.  
  52. function linkcolorchange(step){
  53.   var obj=document.getElementById("fscroller").getElementsByTagName("A");
  54.   if (obj.length>0){
  55.     for (i=0;i<obj.length;i++)
  56.       obj[i].style.color=getstepcolor(step);
  57.   }
  58. }
  59.  
  60. var fadecounter;
  61. function colorfade(step) {
  62.   if(step<=maxsteps) { 
  63.     document.getElementById("fscroller").style.color=getstepcolor(step);
  64.     if (fadelinks)
  65.       linkcolorchange(step);
  66.     step++;
  67.     fadecounter=setTimeout("colorfade("+step+")",stepdelay);
  68.   }else{
  69.     clearTimeout(fadecounter);
  70.     document.getElementById("fscroller").style.color="rgb("+endcolor[0]+", "+endcolor[1]+", "+endcolor[2]+")";
  71.     setTimeout("changecontent()", delay);
  72.    
  73.   }   
  74. }
  75.  
  76. function getstepcolor(step) {
  77.   var diff
  78.   var newcolor=new Array(3);
  79.   for(var i=0;i<3;i++) {
  80.     diff = (startcolor[i]-endcolor[i]);
  81.     if(diff > 0) {
  82.       newcolor[i] = startcolor[i]-(Math.round((diff/maxsteps))*step);
  83.     } else {
  84.       newcolor[i] = startcolor[i]+(Math.round((Math.abs(diff)/maxsteps))*step);
  85.     }
  86.   }
  87.   return ("rgb(" + newcolor[0] + ", " + newcolor[1] + ", " + newcolor[2] + ")");
  88. }
  89.  
  90. if (ie4||DOM2)
  91.   document.write('<div id="fscroller" style="width:'+fwidth+';height:'+fheight+'"></div>');
  92.  
  93. if (window.addEventListener)
  94. window.addEventListener("load", changecontent, false)
  95. else if (window.attachEvent)
  96. window.attachEvent("onload", changecontent)
  97. else if (document.getElementById)
  98. window.onload=changecontent
  99.  
  100. </script></a></td>

Here the style which i am using in the td -

css Code:
  1. .style4 {
  2.     font-family: Verdana, Arial, Helvetica, sans-serif, "Trebuchet MS";
  3.     font-size: 10px;
  4.     font-weight: normal;
  5.     color: #000000;
  6.     background-color: #F4F4F4;
  7.     cursor: pointer;
  8.     vertical-align: middle;
  9.     text-decoration: none;
  10.     text-align: left;
  11. }

Please Help as soon as possible.

- SmartzKool

Last edited by Nico; 10-11-08 at 09:45 AM. Reason: Wrappers.
Reply With Quote
  #2 (permalink)  
Old 10-12-08, 05:43 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
The problem is that you can't place a block element like the div inside a non-block element, the link, while the page is being constructed. Firefox solves this by moving the div tag outside the link. And since it is placed after the link, and it's not possible to z-index sort them because they are not absolutely positioned, the div is placed above the link and covers it.

One way to get around that is to print the link inside the innermost div.
Remove the link from the source, then print it dynamically on the page, here.
JavaScript Code:
  1. document.getElementById("fscroller").innerHTML=begintag+fcontent[index]+closetag
  2. becomes
  3.     document.getElementById("fscroller").innerHTML=begintag+'<a href="page.htm" style="display:block; cursor:pointer; text-decoration:none;">'+fcontent[index]+'</a>'+closetag

Note that search engines won't be able to find the link now as they don't execute scripts. So you might want to place a link to that page somewhere else too in case it's important. Same thing goes for humans if they have JavaScript disabled.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
random link problem doogi PHP 18 03-04-09 01:00 AM
Open a new window in firefox by clicling on a link inside a flash pop up oursvince Flash & ActionScript 5 11-16-07 06:13 AM
link problem jonnekke Flash & ActionScript 7 04-19-07 10:25 AM
unknown problem - probably $session issue clantron PHP 6 03-19-06 01:36 PM
I'm confused..plz help Brittany23 CSS 5 05-24-05 11:52 AM


All times are GMT -5. The time now is 11:44 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.