Can I NOT run a chunk of HTML on javascript-less browsers?

Discussion in 'JavaScript' started by LongHaul, Nov 12, 2007.

  1. #1
    I know it's easy to bypass javascript with the <script> tags, but I have some actual HTML I want to disable.

    Specifically, there is an html div with some stuff in it, and the main thing in it is a javascript thing. If a user has no javascript, I don't want the div box shown at all.

    I tried putting the whole box in a separate php file, and then using:
    <script type="text/javascript" src="separate.php"></script>
    Code (markup):
    but it didn't work.

    Any tips? Thanks!!
     
    LongHaul, Nov 12, 2007 IP
  2. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Just tell JavaScript to draw the div box.
     
    MMJ, Nov 13, 2007 IP
  3. LongHaul

    LongHaul Peon

    Messages:
    670
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yeah, that's what I finally did, put everything I wanted to say, html tags and all, in a big javascript output. Don't know why I had such a mental block against it! It took some character escaping and removal of tabs and linebreaks, but it works fine, check it out here:

    http://music-nerds.com/album.php?id=1910

    It's the "Widget" box down the page; you won't see that box if you have javascript disabled.

    Thanks anyway MMJ!
     
    LongHaul, Nov 13, 2007 IP
  4. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    np. :)

    The reason why the "whole box in a separate php file" solution didn't work is possibly because you weren't serving the page as javascript. To do so you would have to add this in the beginning:

    
    header('Content-type: application/javascript');
    
    PHP:
     
    MMJ, Nov 13, 2007 IP
  5. LongHaul

    LongHaul Peon

    Messages:
    670
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Ah, didn't think of that. Thanks. Fortunately, what I needed was small, and the solution you mentioned before worked like a charm!
     
    LongHaul, Nov 13, 2007 IP