Reputation: 4706
Suppose I have a URL like www.google.com
, and I want Javascript/JQuery on my page to go see what is in the <title>
for the content of that URL, and put it into a variable for me. How can I make it work?
Upvotes: 3
Views: 923
Reputation: 17181
This will also work for you. I'm not sure how a match
compares, performance-wise, against the other options here:
var html_title = html.match("<title>(.*?)</title>")[1];
Upvotes: 1
Reputation: 16223
You can try something like:
var title = document.title;
After seeing your edited question I guess what you wanted as the others remark is:
jQuery.get('<url of the page you want>', function(data) {
var title = jQuery(data).title;
});
Upvotes: 4
Reputation: 57322
try
var titles = document.getElementsByTagName('title')
try to det title from url
$.get(document.URL, function(demo) { //or window.location.href to get the url of currec\nt page
var title = $(demo).title;
});
Upvotes: 2
Reputation: 35409
given the url is of the same origin:
$.get('page.html', function(text) {
var pagetitle = $(text).title;
});
Upvotes: 8