Reply
Dectecting if Javascript is enabled
Old 07-03-2006, 07:38 PM Dectecting if Javascript is enabled
Skorch's Avatar
Super Talker

Posts: 115
Location: California
I basically want to end the loading of a page if javascripting is disabled. Yes I pretty much want to show blank pages to users who have not detected JavaScripting.

I thought about including a php tag using exit; in a noscript tag
Code:
<noscript>
<?php 
echo 'This page REQUIRES JavaScripting to be enabled';
exit;?>
</noscript>
but wondered if this would affect users with JavaScripting enabled.

My question is will the server parse the php tag when it encounters it or will it only parse the php tag when the noscript tag is used when a visitor's JavaScripting is disabled?
__________________
Check out my Cliff Diving website!
Skorch is offline
Reply With Quote
View Public Profile Visit Skorch's homepage!
 
Sponsored Links (We share ad revenue):
 
Old 07-04-2006, 12:42 AM Re: Dectecting if Javascript is enabled
funkdaddu's Avatar
Web Design Snob

Posts: 636
PHP can't detect that. How about calling a PHP script with a .js command? That way if they don't have JS on, then the PHP script won't be called.

But really you should make it work without JS at all if you can, as a backup.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 07-04-2006, 05:42 AM Re: Dectecting if Javascript is enabled
Minaki's Avatar
Cheerleader

Posts: 1,626
Location: Guildford, UK
What you need to bear in mind is the order in which things are done on the web. The PHP Script is parsed by the server before the resulting HTML is even sent to the browser. Therefore, tags such as <noscript> have no effect at the time the PHP is being parsed. Think of any HTML outside the <? ?> tags as being echo'd by PHP, i.e.
Code:
<?php
echo '<noscript>'; ?> <?php echo 'This page REQUIRES JavaScripting to be enabled'; exit;?> <?php echo '</noscript>'; ?>
That code will create an HTML document which will then be parsed by the browser. But since you have an exit statement in there, the </noscript> end tag will never be written out. All you will end up with is invalid html.
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Inoxia Pyrotechnics Supplies | Surrey Angels Cheerleading Squad

Last edited by Minaki : 07-04-2006 at 05:45 AM.
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 07-07-2006, 02:05 PM Re: Dectecting if Javascript is enabled
Skorch's Avatar
Super Talker

Posts: 115
Location: California
Wow the more I learn about JavaScript the more I would rather use PHP.

My problem

I wanted to use JS to read this XML data onto a webpage

Code:
<userlist>
 <member>
  <name>Bob Jones</name>
  <motto>Every day in every way I get better &amp; better!</motto>
  <id_number>1369420</id_number>
 </member>
</userlist>
So here's my well thought out solution. XML is a waste of time and largely unsupported so why bother? I'll just rename the XML file to members.TXT and replace the XML tags with (X)HTML tags and then use PHP includes to add the file to my page. I'm done, though I'm not proud, and I didn't have to use any JS or regex expressions.
__________________
Check out my Cliff Diving website!
Skorch is offline
Reply With Quote
View Public Profile Visit Skorch's homepage!
 
Old 07-07-2006, 03:19 PM Re: Dectecting if Javascript is enabled
funkdaddu's Avatar
Web Design Snob

Posts: 636
JS is for manipulation of the page after it has been sent to the user. (client-side)
PHP is for manipulating of the page before it reaches the user. (server-side)

They really have 2 separate uses.

JS has support for XML. No use of regexs to parse an XML file:
Code:
var theXML = req.responseXML.getElementsByTagName("userlist");
var theMembers = theXML[0].getElementsByTagName("member");
var firstUsername = theMembers[i].getElementsByTagName("name")[0].firstChild.nodeValue;
That's what all the AJAX hubub is about. But unless you need to insert the name/motto/uid after the page has loaded, just make a DB and use PHP. Better security too.

Last edited by funkdaddu : 07-07-2006 at 03:22 PM.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 05-09-2008, 06:31 AM Re: Dectecting if Javascript is enabled
Junior Talker

Posts: 3
Name: jon
I have some code which detects javascript with php.
It can be found at
http://snippets.bluejon.co.uk/
blujon
bluejon is offline
Reply With Quote
View Public Profile
 
Old 05-09-2008, 07:14 AM Re: Dectecting if Javascript is enabled
tripy's Avatar
Fetchez la vache!

Latest Blog Post:
Pretty pretty please….
Posts: 1,705
Name: Thierry
Location: In the void
Quote:
XML is a waste of time and largely unsupported so why bother?
As a programmer having several years of experience on this field, XML is far from being unsupported and a waste of time.

When you do things in your little corner, it might by overkill, but as soon as you need to exchange datas between differen systems (or applications) you don't manage, it's literraly a savior.

Probably you are throwing it because you were not using it in the right situation, or with the good approach, but trust me, it's VERY easy and fast to alter it to render nearly anything.

I develop every sites I do with XML and XSLT, and it does have reduced the templating and code handling time I spent on my pages.

And by the way, if you have heard about the DOM tree of your browser (you know, that thingy firefox include to let you inspect the source of a web page) ?
Well, it's pure XML. Javascript DOM functions are supported in every browser since IE 5.5 (he was the first) and since then almost every modern web browser can create a web page receiving XML and XSL.
__________________
Listen to the ducky: "This is awesome!!!"

tripy is online now
Reply With Quote
View Public Profile
 
Sponsored Links (We share ad revenue):
 
Reply     « Reply to Dectecting if Javascript is enabled
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML


Page generated in 0.17471 seconds with 14 queries