admin管理员组文章数量:1287115
Suppose I have a URL like www.google
, 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?
Suppose I have a URL like www.google.
, 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?
- 1 see stackoverflow./questions/9228947/… – Amol Kolekar Commented Oct 25, 2012 at 13:52
- 1 Are You loading the URL in the browser, or just want to know the title for it? – undefined Commented Oct 25, 2012 at 13:52
- 1 @xyu I just want to know the title for it. – John Commented Oct 25, 2012 at 13:55
- 4 As noted by Xander in his answer, if the page you're wanting to look into is not in the same domain as your page (and I'm pretty sure www.google. isn't!!) then you will hit the Same Origin Policy, which will remove your ability to do this on the browser itself – freefaller Commented Oct 25, 2012 at 14:00
5 Answers
Reset to default 8given the url is of the same origin:
$.get('page.html', function(text) {
var pagetitle = $(text).title;
});
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;
});
$.get(url, function(html) {
var title = $(html).title
});
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;
});
This will also work for you. I'm not sure how a match
pares, performance-wise, against the other options here:
var html_title = html.match("<title>(.*?)</title>")[1];
本文标签: jqueryExtract HTML title in JavascriptStack Overflow
版权声明:本文标题:jquery - Extract HTML title in Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741223460a2361413.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论