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 - function readCookie(name) {
-
alert("i am Reading the cookies");
-
var nameEQ = name + "=";
-
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(nameEQ) == 0)
-
return c.substring(nameEQ.length,c.length);
-
}
-
-
}
-
return null;
-
}
-
-
-
function setFont(c_value)
-
{
-
-
switch(c_value)
-
{
-
case 'big':
-
-
var navNam = navigator.appName;
-
var navVer= parseFloat(navigator.appVersion);
-
-
if (navNam.indexOf('Microsoft') != -1 ) {
-
//IE
-
document.write('<link rel="stylesheet" type="text/css" href="/imagesvariables_fonts_main_ie_big.css" />');
-
} else {
-
//Netscape
-
document.write('<link rel="stylesheet" type="text/css" href="/images/variables_fonts_main_net_big.css" />');
-
}
-
-
-
-
-
-
break;
-
case 'small':
-
var navNam = navigator.appName;
-
var navVer= parseFloat(navigator.appVersion);
-
-
-
if (navNam.indexOf('Microsoft') != -1 ) {
-
//IE
-
document.write('<link rel="stylesheet" type="text/css" href="/images/variables_fonts_main_ie.css" />');
-
} else {
-
//Netscape
-
document.write('<link rel="stylesheet" type="text/css" href="/images/variables_fonts_main_ie.css" />');
-
}
-
-
-
-
-
-
break;
-
-
-
}
-
-
}
-
-
function toggleFont()
-
{
-
var value;
-
value=readCookie("size");
-
var name;
-
var c_value;
-
-
-
switch(value)
-
{
-
-
case 'big':
-
alert("i am inside big");
-
document.cookie ='size=small; expires=Fri, 3 Aug 2020 20:47:11 UTC; path=/';
-
setFont("small");
-
break;
-
-
case 'small':
-
alert("i am inside small");
-
document.cookie ='size=big; expires=Fri, 3 Aug 2020 20:47:11 UTC; path=/';
-
setFont("big");
-
break;
-
-
default:
-
alert("cookie not found!");
-
document.cookie ='size=small; expires=Fri, 3 Aug 2020 20:47:11 UTC; path=/';
-
-
-
}
-
-
}
[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?
13 2254
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.
Even i can see the "downloadin g css file " info in the ie , but after that it gives the blank page.
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.
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.
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
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.
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]
cookie value and style sheet title are not equal at any time, i don understand how it happens, and sorry for taking more space !
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?
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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.
|
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
|
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.
****************************************************************************
|
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.
| |
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...
|
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...
|
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"...
|
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...
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |