473,408 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How to get the value of the HTML title tag?

384 256MB
I was using the below javasciprt code, can the innerHTML be used in PHP? Is it possible to change this code into php?
Expand|Select|Wrap|Line Numbers
  1. function get_title() {
  2.     var t = document.getElementsByTagName('title')[0];
  3.     if ( !!t.childNodes.length ) {
  4.         document.write(t.firstChild.data);
  5.     } else if ( t.innerHTML ) {
  6.         document.write(t.innerHTML);
  7.     }
  8. }
Jan 22 '10 #1
2 3463
dgreenhouse
250 Expert 100+
You can output any type of code that will go into the HTML page using PHP.

Are you trying to get a new page title from the server based on some "on server" processing? If YES, you can make it easier by having a variable defined in JavaScript; I'd suggest an anonymous object or out of GLOBAL scope, and make an AJAX call on a PHP script at the server.

Generating "in page" JavaScript is done all the time.

Although after the code generation is done, there is no longer a connection to the PHP script running on the server. YOU can get very sophisticated and replace JavaScript script tag contents on the fly; even via AJAX calls to a PHP script - as mentioned above.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.   <head>
  3.     <title><?php echo $page_title?></title>
  4.     <script type="text/javascript" src="<?php echo getScript()?>"></script>
  5.     <script type="text/javascript">
  6.       <?php
  7.         // Generate a bunch of JavaScript code here...
  8.       ?>
  9.     </script>
  10.   </head>
  11.   <body>
  12.  
  13.   </body>
  14. </html>
  15.  
Jan 22 '10 #2
dgreenhouse
250 Expert 100+
Sorry for the confusing post... I was very sleep deprived...

A specific line from the original post should be read as:
"I'd suggest an anonymous object or an out of GLOBAL scope variable"
Jan 22 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Scaramouche | last post by:
i have the contents of an html page stored within a variable. i would like to parse out the value of the TITLE tag, ie..<TITLE>this_value_is_what_i_want</TITLE> String title=null; int...
1
by: G Kannan | last post by:
Hey all! I have written a perl script to retrieve information from a HTML Form and insert the data into an Oracle database table. I am gettting the the following error message: "Use of...
1
by: Richard G. | last post by:
Hi All, I am newbie in XML. I am designing a dynamic menu and retrieving data from xml. I have the xml file something like this: <?xml version="1.0" ?> <ROOT>
2
by: dsimonneau | last post by:
Hello all, I would like to call a JSP from a Javascript and get a result on my javascript To call the JSP I'm doing like that : <SCRIPT LANGUAGE="Javascript1.1"> function test() {
16
by: cwizard | last post by:
I'm calling on a function from within this form, and there are values set but every time it gets called I get slammed with a run time error... document.frmKitAmount.txtTotalKitValue is null or not...
6
by: paul | last post by:
HI! How do we send a variable from an Iframe page back to its parent? I have a script that calculates the iframe's window size but I need to know how to send that value back to its parent so I...
2
by: sp | last post by:
hai i am new to this XSTL and i am trying to write xslt that will filter out the xml value based on Attribute Value. my xml looks like this <catalog> <cd> <title year="1990">Empire...
5
by: drdave | last post by:
Hi, I have 6 forms being generated using coldFusion, they are named special1, special2 special3 and so on.. in these forms I have a link to open a new window. I am trying to pickup the...
3
by: lintolawrance | last post by:
sir, i am starting working with php.i done some programs.but now i have one problem.i do a program like to retrieve the name and email from a phpfile to another.but i can't get. this is the code...
5
by: montybytes | last post by:
Hi there, Although, I have already placed this question in the HTML/CSS section, perhaps it might be worthwhile asking the question here as well. I have a JavaScript function which retrieves...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.