Can I do something like the code (which doesn't work) below? I want to return a value from a javascript function to be the title (see the attempted call in the TITLE tag below). How can I tweak this to work? Second question is how do search engines read a site? Will they see the executed function value and index it like that or do they read sites statically (function never executed)? In other words would they index my site with a title of "hi" or a title of "returndata()" based on the code below? Thanks, John <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=utf-8"> <META content="MSHTML 6.00.6000.16481" name=GENERATOR> <STYLE type=text/css> BODY{font-family:verdana, arial, sans-serif} </STYLE> <SCRIPT language=JavaScript type=TEXT/JAVASCRIPT> <!-- function returndata() { return "hi"; } //--> <TITLE>returndata()</TITLE>; </SCRIPT> </HEAD> <BODY></BODY></HTML>
All that does is call a function and does nothing with the result. It does not populate <TITLE> as the <HEAD> section is long gone at that point. Thanks for the thought...
Oh, that's what you're trying to do? Change the title in the browser? If that's what you want, try this: <script> function testfunction() { document.title = "Hi, this is my title"; } </script> <html> <title></title> <body onload = "testfunction();"> <body> </html> Code (markup): Just change the text in the string to what you want and you can also call it using a different event if you want.
Why are you trying to use JavaScript to dynamically write a page title? (By the way, that script is better called using an event handler attached to the window object rather than in the <body> tag.)
Sorry, forgot to mention that I don't want to use document.title. I want to have a value in <title> tag itself. Google isn't indexing with my document.title tag I've dynamically set so I need to set <title>.
johnwerry, It's funny that people are giving you such comprehensive answers on the one hand without mentioning the other, much more relevant part of your question: NO, Google will NOT execute your javascript and thus this will not have the desired effect. You need to either do it serverside (php,asp,etc) or assume it is just for your users and not for the se's. Good luck, -Phil
Actually Phil, I wasn't neglecting the other part of his question. I wanted to make him think about it first. I find it helps the brain learn.
Your server probably doesn't support PHP then. There is a quick and easy test for this however. Open a new file, write the following in it, save it as php-info.php and upload it to your server. Then look at the file in a browser (like you would a regular Web page). <?php php_info(); ?> PHP: Don't put ANYTHING ELSE into the file. Not a DOCTYPE, not an HTML tag, NOTHING. Just what I told you to write. If all you see is that line of code, then your server doesn't support PHP. If you see a LOT of information (presented in a purplish table), then it does. You'll also want to put that file into a password protected folder since it contains VERY sensitive information about your server's configuration.
I get something different than either of your scenarios: Fatal error: Call to undefined function: php_info() in /home/content/r/a/r/obfuscated/html/php-info.php on line 1