473,405 Members | 2,338 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,405 software developers and data experts.

Insert embedded stylesheet as block?

I'm hoping someone can explain this and give a tip what I'm doing wrong.

This doesn't work (simplified for readability):

<style type="text/css">
<SCRIPT TYPE='text/javascript' LANGUAGE='JavaScript'>
if ( navigator.platform.substring(0,3).toLowerCase() == 'win')
document.write('body { font-family: Arial} ')
else document.write('body {font-family: Gadget } ')
</SCRIPT>
</style>

But this does:

<SCRIPT TYPE='text/javascript' LANGUAGE='JavaScript'>
if ( navigator.platform.substring(0,3).toLowerCase() == 'win')
document.write('<style type="text/css"> \n' +
'body{ font-family: Arial} \n' +
'</style>')
else document.write('<style type="text/css"> \n' +
'body { font-family: Gadget } \n' +
'</style>')
</SCRIPT>

I've tried to write style text common to both if/else's in the HTML but it
won't work. Why is this? Does JS act differently inside the style tags?

-- Gnarlie
http://www.Gnarlodious.com

Jul 23 '05 #1
2 1398
Ivo
"Gnarlodious" wrote
This doesn't work (simplified for readability):

<style type="text/css">
<SCRIPT TYPE='text/javascript' LANGUAGE='JavaScript'>
if ( navigator.platform.substring(0,3).toLowerCase() == 'win')
document.write('body { font-family: Arial} ')
else document.write('body {font-family: Gadget } ')
</SCRIPT>
</style>

But this does:
<SCRIPT TYPE='text/javascript'>
var font = ( navigator.platform.substring(0,3).toLowerCase() == 'win') ?
'Arial' : 'Gadget';
document.write(
'<style type="text/css"> \n' +
'body{ font-family: '+font+ ' } \n' +
'</style>'
);
</SCRIPT>
I've tried to write style text common to both if/else's in the HTML but it
won't work. Why is this? Does JS act differently inside the style tags?


JS does not act at all inside style tags. Inside style tags only style rules
make sense. It is a pity that we cannot test directly for the presence of
certain fonts on user's system, but why don't you simply write
body{ font-family: Gadget, Arial, sans-serif; }
so that the next is used if the first does not exist?
HTH
Ivo

Jul 23 '05 #2
Entity Ivo spoke thus:
JS does not act at all inside style tags. Inside style tags only style rules
make sense. It is a pity that we cannot test directly for the presence of
certain fonts on user's system, but why don't you simply write
body{ font-family: Gadget, Arial, sans-serif; }


I guess I'll do that. Thanks for verifying what I suspected.
-- Gnarlie
http://www.Spectrumology.com
Spectrumology is the science of chaos.
Jul 23 '05 #3

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

Similar topics

4
by: Wim Roffal | last post by:
On my webpage (http://www.classiccat.net/index.htm) I tried to transfer the cellpadding/spacing attributes to my stylesheet. However, somehow it doesn't work. I tried to look it up on the internet,...
5
by: aamirghanchi | last post by:
Hi, I have a very simple html that has a linked stylesheet. According to the style sheet both blocks of text should be displayed in the font xx-small. but only one (DIV or SPAN) at a time is...
7
by: pintihar | last post by:
Hi, As a follow on from an earlier post I have another question about xslt. Is it possible to create the stylsheet programatically? Is this sensible? In the first phase I needed to map element...
3
by: RD | last post by:
My app transmits XML data file via e-mail and for now I attach both the XML data file and the corresponding style sheet. I found however that whenthe recipient double clicks on the XML file to read...
5
by: nutsmuggler | last post by:
Hi. I am using xml to store my annotations. here is my document (a part of it): <?xml version="1.0" encoding="UTF-8"?> <text title="Finnegan's wake"> <book number="1"> <chapter number="5">...
0
by: michga | last post by:
Hello, Using docbook 4.4, docbook-xsl 1.70.1 and fop, I've successfully used this snippet of code in a customized-layer stylesheet to insert one linebreak: <xsl:template...
1
by: erictomlinson | last post by:
I'm dying here trying to figure this out for days. Here's the scenario: 1) External script.as file dynamically imported to loader.swf file that creates a textfield (createTextField) 2)...
3
by: Waruna | last post by:
Is there a way to block insert into mysql(5.0) using c api of mysql db.. i.e. say there is a table with 2 columns, one contains char other int then i want to insert 500 records at once,, as i...
1
by: msarora | last post by:
I'm using SimpleTransform.java (renamed as ReceiptTransformer.java for custom use) found in xalan-j_2_7_0 samples directory for transformations in my custom application. The program compiles...
2
by: Paulson | last post by:
HI all I got a problem with my menu display.I am making a list as shown below in one of my aspx pages. And added a stylesheet in CSS for it. This is not working in IE but not in...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...
0
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...

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.