[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

get title of the current page using javascript

Posted on 2010-04-06
8
Medium Priority
?
340 Views
Last Modified: 2013-11-11
hi guys,anyone can help me how to get title of the current page using javascript and the value of title will be using  in the php script because i want to save the title in database
0
Comment
Question by:agilentwax
8 Comments
 
LVL 1

Expert Comment

by:mozeruk
ID: 29888717
document.title gives you the text content of the <title> element. You
can also set document.title in most current browsers.

The element itself can be accessed like any other element using e.g.
var titleElement;
if (document.getElementsByTagName) {
titleElement = document.getElementsByTagName('title')[0];
if (titleElement) {
// use titleElement here e.g.
alert(titleElement.nodeName);
}
}
0
 
LVL 22

Expert Comment

by:Om Prakash
ID: 29889118
You can use HIDDEN variable to store the value on click of submit button which can be later used to store the information in database.
//Call this function on click of button
function SaveTitle()
{
document.form[0].yourhiddenfield.value = document.title;
}

You can use yourhiddenfield in the PHP code to save in DB.
0
 

Author Comment

by:agilentwax
ID: 29892390
hai mozeruk and om prakash p, i have use this code <script language="JavaScript">
alert(document.title);</script>  to get the title of the page,it i dont want the popup to display on the page..how to only get the title without the popup..

mozeruk,i have try ur code but i need to set the title rite..and om prakash can u show me how to use ur code u means i need to have input button rite..
eg. <input type="submit" name="submit" value="bookmark" onclick="SaveTitle()"/>
and how to use hidden field to save in db
title.png
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 14

Expert Comment

by:Dhanasekaran Sengodan
ID: 29896377
create a hiddencontrol


<input type="hidden" name="hidtitle" />

function SaveTitle()
{
document.form[0].hidtitle.value = document.title;
}





0
 
LVL 22

Accepted Solution

by:
Om Prakash earned 1500 total points
ID: 29897226

<script>
function SaveTitle()
{
document.form[0].hidtitle.value = document.title;
document.form[0].submit();
}
</script>

<form method="post">
<input type="hidden" name="hidtitle" />
<input type="submit" name="submit" value="bookmark" onclick="SaveTitle()"/>
</form>

Open in new window

0
 

Author Comment

by:agilentwax
ID: 29984674
thnks om prakash, i have try ur code..but i dont get any value from it....can i get the value from javascript without using hidden control or form i means by using this

$title="<script language="JavaScript">alert(document.title);</script>";

i want use the value in $title in href code like this <a href="insert.php?gid=<? echo $gid ?>&sid=<? echo $sid?>&url=<? echo $url?>&tit=<?php $title ?>&id=<? echo $id ?>"
0
 

Author Comment

by:agilentwax
ID: 30086073
so om prakash just ignore my last comment..so now i use ur code to get the title of the page..but it not return any value on the url
0
 

Author Closing Comment

by:agilentwax
ID: 31711260
it give me some idea  to solve my problem
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question