Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibrarySecurity and Blocking

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Convert Text to JavaScript

One reason for using JavaScript to publish content on web pages is to evade the attention of certain types of robots. (The text to JavaScript conversion software that comes with this article can be used to create the JavaScript.)

Form spamming robots, for example, won't find the word "form" or "input" in the web page source code, or other words directly associated with forms. When no form is found, they can meander to another URL on their list.

Primitive bots sent out to fetch the content of a web page are likely to omit JavaScript.

Another reason for using JavaScript to publish content is to make it available only if the browser has JavaScript turned on. Perhaps you wish to publish links to games or other content that can work only with JavaScript. Or you wish to publish content only when the page is loaded in a certain browser.

Search engine spiders probably won't skip over JavaScript, like they used to a few years ago, especially the more popular ones. Thus, except for primitive search spiders or spiders designed to specifically omit JavaScript, this is unlikely to be an effective search blocker. If certain words or phrases need to stay out of search results it may be better to employ a different technique, such as presenting the text as an image.

To convert text to JavaScript, you can:

The content published with JavaScript may be a word, a phrase, a paragraph, or an entire article.

Here is the complete PHP web page to convert text to JavaScript. No customization is required.

<!DOCTYPE html>
<html lang="en">
<head>
<title>Text to JavaScript Converter</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
body { font-family:sans-serif; margin:50px 0 50px 100px; }
textarea { width:100%; height:12em; box-sizing:border-box; }
input { width:100%; box-sizing:border-box; }
a { text-decoration:none; }
p { line-height:130%; }
</style>
</head>
</body>
<div style="max-width:500px; margin:.25in auto;">
<a href="http://www.willmaster.com/">
<img src="http://www.willmaster.com/images/wmlogo_icon.gif" style="width:50px; height:50px; border:none;" alt="Willmaster logo">
</a>
<h3>Text to JavaScript Converter</h3>

<?php
if( empty($_POST['text']) ) { $_POST['text'] = ''; }
if( isset($_POST['submitter']) )
{
   $_POST['text'] = stripslashes($_POST['text']);
   $_POST['text'] = trim($_POST['text'],"\r\n");
   echo <<<TOPPARTRESPONSE
<p>
The JavaScript converted from text is in this box. 
Paste it into the source code where it is to be published.
</p>
<textarea name="_blank" onclick="select()" wrap="off" style="white-space:pre;">
&lt;script type="text/javascript"&gt;\n
TOPPARTRESPONSE;
   foreach( explode("\n",str_replace("\r",'',$_POST['text'])) as $line )
   {
      $js = $line;
      $js = preg_replace('/<\?php[^>]+?\$_SERVER\[\'PHP_SELF\'\][^>]+?\?'.'>/','PHP_SELF-FLES_PHP',$js);
      $js = str_replace("\\","\\\\",$js);
      $js = str_replace("'","\\'",$js);
      $js = str_replace("<!--","<'+'!--",$js);
      $js = str_replace("-->","--'+'>",$js);
      $js = preg_replace('/(spa)(m)/i','$1\'+\'$2',$js);
      $js = preg_replace('/(for)(m)/i','$1\'+\'$2',$js);
      $js = preg_replace('/(typ)(e)/i','$1\'+\'$2',$js);
      $js = preg_replace('/(inp)(ut)/i','$1\'+\'$2',$js);
      $js = preg_replace('/(emb)(ed)/i','$1\'+\'$2',$js);
      $js = preg_replace('/(sel)(ect)/i','$1\'+\'$2',$js);
      $js = preg_replace('/(act)(ion)/i','$1\'+\'$2',$js);
      $js = preg_replace('/(scr)(ipt)/i','$1\'+\'$2',$js);
      $js = preg_replace('/(win)(dow)/i','$1\'+\'$2',$js);
      $js = preg_replace('/(doc)(ument)/i','$1\'+\'$2',$js);
      $js = preg_replace('/(tex)(tarea)/i','$1\'+\'$2',$js);
      $js = preg_replace('/PHP_SELF-FLES_PHP/',"'+document.URL+'",$js);
      echo "document.writeln('$js');\n";
   }
   echo <<<BOTTOMPARTRESPONSE
&lt;/script&gt;
</textarea>
BOTTOMPARTRESPONSE;
}
?>

<p style="margin-top:2em;">
In this box, type or paste the text to convert:
</p>
<form method="post" action="<?php echo($_SERVER['PHP_SELF']); ?>">
<textarea name="text" wrap="off" style="white-space:pre;"><?php echo(htmlspecialchars($_POST['text'])); ?></textarea>
<p>
<input type="submit" name="submitter" value="Convert to JavaScript" />
</p>
</form>

</div>
</body>
</html>

Save the above source code as any web page file name ending with .php and upload it to your server. To use the software, type its URL into your browser.

Perhaps some of the reasons to publish content with JavaScript given in this article are reasons that affect your website.

If yes, convert the relevant text into JavaScript with the demonstration installation or install the JavaScript converter on your server.

(This content first appeared in Possibilities newsletter.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC