How to extract a website TITLE, META KEYWORDS and META DESCRIPTION by javascript for example site has exactly extracts [] websites TITLE, META KEYWORDS and META DESCRIPTION. How to do it by javascript mainly in HTML? Thankyou!

Recommended Answers

All 10 Replies

Well, assuming you really want JS, you can just do document.getElementsByTagName('title') and ...('meta'). If you actually get this info on another server, without running any code from that page, what I would find more logical, you could use an XML parser or just some regular expression to get the info.

actually i am new to coding!
so if you give me a example or refer any article that will better for me.

Thanks twiss,
suppose if i want to extract "Title" then what changes needed for below code?

function getTitle($Url){
	$str = file_get_contents($Url);
		return $title[1];
echo getTitle("http://localhost/");

here i am showing you a code that extract a page TITLE, DESCRIPTION perfectly.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="" xml:lang="en" lang="en">
<title>amar titkle</title>
 <meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="description" content="shob kisur bornona" />
<meta name="keywords" content="eta ki, googl , bd, in" />
<style type="text/css">
#Box{border:1px solid #000044;text-align:center;background-color : #fff;} 
#green {color:green }
<body><h1>Niche Dekhun</h1><br />
<div id="Box">
<script type="text/javascript">
var a = (document.title);
var b = (document.location.href);
var c = document.getElementsByTagName('meta');
var description;
for (var x = 0, y = c.length; x < y; x++) {
    if (c[x].name.toLowerCase() == "description") {
        description = c[x];
document.write('<a href="' + b + '">' + a + '<\/a><br />' + description.content + '<br />');
document.write('<span id="green">' + b + '<\/span>');

What then if i want to extract TITLE, DESCRIPTION of a URL by this above code in my website? What types of changes i need to do in this code?
Hoping a great response!

Merging this with your other thread for the same question.

Please do not scatter the discussion over multiple threads.

this is a new code i find over net, so it can'?@Ezzaral

It is still basically the same question. Spreading that across many threads just creates a cluttered mess and people may waste their time typing duplicate suggestions that have already been given in another thread.

only javascript can do that document.title and document.getElementsByTagName('meta') will do the job .. load this code into the 2 var needed

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.