Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Document.write & Noscript Questions (javascript)
gaea
post May 8 2008, 12:26 AM
Post #1


Super Member
*********

Group: Members
Posts: 205
Joined: 14-March 06
From: Vermont or Boston (USA)
Member No.: 20,077



I am trying to use javascript to include a stylesheet depending on the user's resolution.

The HTML
CODE
<head>
   <meta http-equiv="Content-Type" content="text/html; <?php echo _ISO; ?>" />
   <?php if ($my->id) { initEditor(); } ?>
   <?php mosShowHead(); ?>
   <noscript><link rel="stylesheet" type="text/css" href="http://www.highimpactart.org/templates/_HighImpactArt_/1024/1024.css" /></noscript>
   <script type="text/javascript">
       if (screen.width>=1050) { document.write('<link rel="stylesheet" type="text/css" href="http://www.highimpactart.org/templates/_HighImpactArt_/1280/1280.css" />'); }
   </script>
   </head>


I'm running into two problems.

1) The script doesn't seem to be writing anything. Fixed
2) The <noscript> tags cause all sorts of validation errors. From what I've read it seems as though the <noscript> tag is not allowed within the <head> section -- is this correct? Could the same thing be accomplished just putting the default stylesheet above the javascript? The 1280 stylesheet has the same exact classes as the 1024 stylesheet, so would that over ride it?
3) The Validator doesn't like the fact that I have a "link" element inside the javascript code. Any suggestions about how to fix it? Evidently xhtml doesn't play nice with javascript by default. You need to add in two extra lines.

Ie:
CODE
<script type="text/javascript">/*<![CDATA[*/
     YourJavaScriptCodeHere
/*]]>*/</script>



Thank you for your time.

This post has been edited by truefusion: May 8 2008, 10:01 PM
Go to the top of the page
 
+Quote Post
rvalkass
post May 8 2008, 07:21 AM
Post #2


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,056
Joined: 28-May 05
From: Hertfordshire, England
Member No.: 7,593
Spam Patrol



QUOTE(gaea @ May 8 2008, 01:26 AM) *
2) The <noscript> tags cause all sorts of validation errors. From what I've read it seems as though the <noscript> tag is not allowed within the <head> section -- is this correct? Could the same thing be accomplished just putting the default stylesheet above the javascript? The 1280 stylesheet has the same exact classes as the 1024 stylesheet, so would that over ride it?


The noscript element can only go in the body, as either an inline or block level element. Stylesheets do cascade, meaning that a second stylesheet will overwrite the first. You could therefore always include the 1024 stylesheet, and just use JS to put in the 1280 stylesheet if necessary.

QUOTE(gaea @ May 8 2008, 01:26 AM) *
3) The Validator doesn't like the fact that I have a "link" element inside the javascript code. Any suggestions about how to fix it? Evidently xhtml doesn't play nice with javascript by default. You need to add in two extra lines.

Ie:
&lt;script type="text/javascript">/*<![CDATA[*/
YourJavaScriptCodeHere
/*]]>*/</script>
Thank you for your time,
~Paolo


You shouldn't have the /* in your code there. It should just be:
CODE
<script type="text/javascript">
<![CDATA[
    Some JS here...
]]>
</script>
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Javascript Slideshow Tutorial(3)
  2. Javascript Close Window(12)
  3. One Click Copy And Paste To Clipboard(5)
  4. Adding Rows & Columns In Html Table Using Javascript(1)
  5. I'm Making My Own Javascript Only Rpg :d(7)
  6. What's The Relationship Between Javascript And Java(5)
  7. Javascript : No Right Click Script !@(12)
  8. Hiding <div> Boxes With Javascript(8)
  9. A Simple Javascript Help Required(3)
  10. Help With Javascript Calculator On My Website Please!(1)
  11. My Little Javascript(0)
  12. Highlight A Word In Javascript. Help!(2)
  13. How Do You Make A Javascript Calculator?(11)
  14. Help With Javascript Calculator Returning "nan"(2)
  15. Great Javascript Script Source(2)
  1. Web Applications: J2ee Or Javascript/css/html(1)
  2. Opera Browser + Javascript + Embeded Sound(0)
  3. Javascript - What's Your Browser?(3)
  4. Javascript Events Not Working For Ie(6)
  5. I`m New To Javascript.(5)
  6. Special Wii Javascript(2)
  7. Javascript Error(2)
  8. Is It Possible To Create A Web Based Mmo In Javascript?(4)
  9. Capturing Username Of Computer(3)
  10. Javascript Object Node Referencing Help(5)
  11. Flash And Javascript Interaction(1)
  12. Java Vs Javascript(11)
  13. Adjusting Rows/cols Of Frames In Frameset Using Javascript Is Not Working In Firefox 3 Is Not Working(4)


 



- Lo-Fi Version Time is now: 26th July 2008 - 02:43 PM