Enable Javascript Dynamically

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
romepatel
Forum Newbie
Posts: 1
Joined: Tue Nov 10, 2009 12:25 am

Enable Javascript Dynamically

Post by romepatel »

Hello,

I am new to PHP development,
I am using javascript in my PHP pages,
so i want to enable javascript dynamically by clicking a link in <noscript> <a >enable javascript</a></noscript> and refreshing the page by enabling the javascript.
:banghead:
Please can any help me out


Thanks in advance
ceiroa
Forum Newbie
Posts: 11
Joined: Thu Oct 08, 2009 4:14 pm

Re: Enable Javascript Dynamically

Post by ceiroa »

I think the simplest way to do this would be to some PHP code at the top of the page that would read a GET parameter:

Code: Select all

 
$javascriptEnabled = $_GET['jvsEnabled'];
 
PHP would output the whole HTML page, but would only include the javascript if the link to enable it was clicked, and would include the link to enable javascript in the HTML:

Code: Select all

 
echo '
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Title here</title>';
 
if($javascriptEnabled==true) {
   echo "<script src="js/myJsCode.js" type="text/javascript"></script>";
}
 
echo '
    </head>
    <body>
        <a href="thissamepage.php?jvsEnabled=true">Enable JavaScript</a>
    ...
    </body>
</html>';
 
---------------
Carlos R. M. Eiroa
PHP Consultant
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Enable Javascript Dynamically

Post by pickle »

You cannot enable Javascript from a webpage. The best you can hope for is an instruction to the user to enable Javascript themselves.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply