473,785 Members | 2,374 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ie gives a blank page with the below script, but fire fox works fine

40 New Member
Hi All
i am trying to change the font of my web page with user preference.i made use of cookie to get the user's preference, so that the font size selected will remain for the next session. i am changing the style sheet with the cookie set, The below shown is my code


Expand|Select|Wrap|Line Numbers
  1. function readCookie(name) {
  2.         alert("i am Reading the cookies");
  3.         var nameEQ = name + "=";
  4.         var ca = document.cookie.split(';');
  5.  
  6.         for(var i=0;i < ca.length;i++) {
  7.               var c = ca[i];
  8.              while (c.charAt(0)==' ')
  9.                 {
  10.                 c = c.substring(1,c.length);
  11.                 if (c.indexOf(nameEQ) == 0)
  12.                 return c.substring(nameEQ.length,c.length);
  13.                }
  14.  
  15. }
  16. return null;
  17. }
  18.  
  19.  
  20. function setFont(c_value)
  21. {
  22.  
  23. switch(c_value)
  24. {
  25. case 'big':
  26.  
  27. var navNam = navigator.appName;
  28. var navVer= parseFloat(navigator.appVersion);
  29.  
  30. if (navNam.indexOf('Microsoft') != -1 ) {
  31.         //IE 
  32.         document.write('<link rel="stylesheet" type="text/css" href="/imagesvariables_fonts_main_ie_big.css" />');
  33. }    else {
  34.         //Netscape
  35.         document.write('<link rel="stylesheet" type="text/css" href="/images/variables_fonts_main_net_big.css" />');
  36. }
  37.  
  38.  
  39.  
  40.  
  41.  
  42. break;
  43. case 'small':
  44. var navNam = navigator.appName;
  45. var navVer= parseFloat(navigator.appVersion);
  46.  
  47.  
  48. if (navNam.indexOf('Microsoft') != -1 ) {
  49.         //IE 
  50.         document.write('<link rel="stylesheet" type="text/css" href="/images/variables_fonts_main_ie.css" />');
  51. }    else {
  52.         //Netscape
  53.         document.write('<link rel="stylesheet" type="text/css" href="/images/variables_fonts_main_ie.css" />');
  54. }
  55.  
  56.  
  57.  
  58.  
  59.  
  60. break;
  61.  
  62.  
  63. }
  64.  
  65. }
  66.  
  67. function toggleFont()
  68. {
  69. var value;
  70. value=readCookie("size");
  71. var name;
  72. var c_value;
  73.  
  74.  
  75. switch(value)
  76. {
  77.  
  78. case 'big':
  79. alert("i am inside big");
  80. document.cookie ='size=small; expires=Fri, 3 Aug 2020 20:47:11 UTC; path=/';
  81. setFont("small");
  82. break;
  83.  
  84.  case 'small':
  85.  alert("i am inside small");
  86.   document.cookie ='size=big; expires=Fri, 3 Aug 2020 20:47:11 UTC; path=/';
  87.   setFont("big");
  88.   break;
  89.  
  90. default:
  91. alert("cookie not found!");
  92. document.cookie ='size=small; expires=Fri, 3 Aug 2020 20:47:11 UTC; path=/';
  93.  
  94.  
  95. }
  96.  
  97. }    
[HTML] //-->
</script>
<a class=pagenav href="#" onClick="javasc ript:toggleFont ();" >Text size</a></span>
[/HTML]


but the above code works in fire fox, but it is gives a blank page in ie,can any one help me with the issue?
Aug 3 '08 #1
13 2254
Revathi Balakrishnan
40 New Member
when the user clicks on the Text size link it will call the Toggle font function, that will read the cookie value using readCookie function, if the cookie value set is small it will change it to big and the the call the setFont function,

My problem occurs in the setFont function, it goes inside the proper case of the set Font function, after that it gives a blank page in ie, but in fire fox it works fine,

Any of your advise would be much appreciated.
Aug 3 '08 #2
Revathi Balakrishnan
40 New Member
Even i can see the "downloadin g css file " info in the ie , but after that it gives the blank page.
Aug 3 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
You can't use document.write after the page has loaded. It will open the document again for writing which is not what you want. For using alternate stylesheets with cookies, see this link.
Aug 3 '08 #4
acoder
16,027 Recognized Expert Moderator MVP
Two more quick points:

If all you want is to change a couple of style rules, use elem.style.colo r instead of changing the whole stylesheet.

Don't use browser detection. There's no need for it here.
Aug 3 '08 #5
Revathi Balakrishnan
40 New Member
Hi the link which you have given is really very useful.Timely help!!!!!!!!

i am working on it. i will send you the feed back soon. But i could not under
stand your second reply mail. Could you please elaborate that
Aug 4 '08 #6
acoder
16,027 Recognized Expert Moderator MVP
Sorry, elem.style.colo r should have been elem.style.font Size. If you only need to change a few elements, then use JavaScript to change the font size - see link. This is a lot better than changing the whole stylesheet. If, however, there a quite a number of changes, it might be better to change the stylesheet. Good design helps here.

Secondly, browser detection (e.g. using navigator.appNa me) is often misused. It is rarely needed. Use feature detection instead- see this link for a good explanation.
Aug 4 '08 #7
Revathi Balakrishnan
40 New Member
i have changed my code to as shown below:

but still it is not working.Help me if you see any bug in it,
[HTML]<link rel="stylesheet " type="text/css" rel="stylesheet " title="big" href="/images/variables_fonts _main_ie_big.cs s"/>

<link rel="stylesheet " type="text/css" rel="stylesheet " title="small" href="/images/variables_fonts _main_ie.css"/>



<script type="text/JavaScript">




function readCookie(name ) {
alert("i am Reading the cookies");
var nameEQ = name + "=";
alert(nameEQ);
var ca = document.cookie .split(';');

for(var i=0;i < ca.length;i++) {

var c = ca[i];


while (c.charAt(0)==' ')
{
c = c.substring(1,c .length);
if (c.indexOf(name EQ) == 0)
return c.substring(nam eEQ.length,c.le ngth);
}

}
return null;
}



function setFont(c_value )
{
var i, a, main;

switch(c_value)
{
case 'big':

alert("i am inside big");

for(i=0; (a = document.getEle mentsByTagName( "link")[i]); i++)
{
alert(" i am inside for loop");
if(a.getAttribu te("rel").index Of("style") != -1&&a.getAttribu te("title"))
{
alert ("i am inside the if")

a.disabled = true;

if(a.getAttribu te("title") == c_value)
{

alert(title);
a.disabled = false;

}

}

}




break;
case 'small':
document.cookie ='size=big; expires=Fri, 3 Aug 2020 20:47:11 UTC; path=/'

alert("i am inside small");

for(i=0; (a = document.getEle mentsByTagName( "link")[i]); i++)
{
alert("i am inside the for loop");

if(a.getAttribu te("rel").index Of("style") != -1 && a.getAttribute( "c_value"))
{
a.disabled = true;

alert(c_value);

if(a.getAttribu te("title") == c_value)

alert(c_value);

a.disabled = false;
}
}

break;


default:

alert("Cookie not found!");

document.cookie ='size=big; expires=Fri, 3 Aug 2020 20:47:11 UTC; path=/'




}

}




var size;
var value;
var navNam = navigator.appNa me;
var navVer= parseFloat(navi gator.appVersio n);
value=readCooki e("size");
alert("value of font_size cookie is"+value);
setFont(value);

</script>[/HTML]
Aug 4 '08 #8
Revathi Balakrishnan
40 New Member
cookie value and style sheet title are not equal at any time, i don understand how it happens, and sorry for taking more space !
Aug 4 '08 #9
acoder
16,027 Recognized Expert Moderator MVP
Did you follow the steps laid out in the link properly?

I notice you have duplicate rel attributes.

What happens with the code you've posted? Do you get any errors?
Aug 4 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1905
by: Trent | last post by:
Hey All, I am new to javascript and currently coding a site with scripts that are beyond my level of understanding. The problematic page has thumbnail images that can be clicked on to zoom in. When clicked, the preloaded larger image displays in a div layer that gets turned on. The problem is that ie sometimes does not display the image - the placeholder just stays blank. The script works fine in firefox and netscape (haven't tried...
6
3018
by: Tony K | last post by:
I have the most peculiar problem with an ASP.NET page which we use for downloading a file. When the user clicks on a link, the link points to an ASPX page which downloads the file selected. The code works fine except after the user saves the file, the links on the left side of the frameset do not work. IE locks up.
1
1663
by: Tebogo Tefo via .NET 247 | last post by:
Hi I have a user control that contains three dropdownlists that I populate according to what was selected in the other dropdownlist (i.e. populate dropdownlist2 after selecting a value in dropdownlist1) The App works fine if I don't add the user control that I created and all events on the page work and thus the App is perfect. But as soon as I add my user control (Here used as the TopNav for my page) all
9
4923
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work fine from a link. The button does bring up the popup window, but when I press the links on the page, it doesn't return or close the window. ****************************************************************************
13
4010
by: kurtj | last post by:
Hello Gurus: I have a validation script (below) that is somehow messed up. If the Name field is blank, I get the alert message, then the browser window goes to a blank document with the word "false" on it. What the ?!?!?! To test, I commented out the 'return false;' code in the second IF block, so now if there is a value in Name then I get the alert message for Email and the page stays put.
6
1537
by: massic80 | last post by:
Hi, it's me again! I have a strange problem with a form I gotta (dynamically) insert in a site, and copied/pasted the code to a blank page, to make it easier to try it out. I was using the $ function of script.aculo.us, which is substituted by the equivalent document.getElementById in the code below (and the problem is still the same). The "mystery" is that this code WORKS both in FF 2 and IE 6, but IE gives an error at the moment when...
0
1610
by: manywolf | last post by:
I have an aspx page that fires the page load event twice for every load. I tried every fix that was suggested in all the posts on this and other forums. None changed the behavior. After one post that suggested they had an img tag with src="", I decided to look for instances of "src" and one by one start removing that code to see if it changed anything. Below is the one that, when I removed it, although it broke the flash menus and header, solved...
13
2973
by: raamay | last post by:
i have the following code which is generated from a .dwt template. My problem is that the page loads but only the header part displays and rest of the contents are not displayed. Everything works fine in my local testing server but when i upload it the hosting server the problem surfaces. I am not sure why? Please kindly go through my code below: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
0
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9483
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10346
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10157
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10096
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9956
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8982
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.