使用Javascript / jQuery的$。获得(URL)名称解析无法正常工作 [英] Javascript / jQuery $.get(url) Title Parsing not Working
问题描述
尽管以下工作: http://jsfiddle.net/N7D5r/
我试图用同样的code 不正确获得冠军。他们返回null,不管是什么奇怪的原因:
My attempt at using the same code does not correctly get the titles. They return null, for whatever strange reason:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
// Act on each link
$('a').each(function(eachIteration){
// Store current link's url
var url = $(this).attr("href");
$.get(url, function(response){
alert("This is the url: " + url);
if (((/<title>(.*?)<\/title>/m).exec(response)) != null)
alert("This would be the title: " + (/<title>(.*?)<\/title>/m).exec(response)[1]);
else
alert("title was null");
});
});
});
</script>
<title>test</title>
</head>
<body>
<p><a href="javascript:;">Javascript link</a></p>
<p> <a href="http://www.latentmotion.com">Misc. Link</a> and what else... <a href="http://www.latentmotion.com/how-to-create-a-jquery-bookmarklet/#comment-52004762">jQuery Bookmarklet Link</a></p>
<p> Some <a href="#test">anchor link</a> test.</p>
</body>
</html>
任何想法?
请注意: 这个问题是在位于这里的堆栈溢出问题跟进: <一href="http://stackoverflow.com/questions/2911930/jquery-cant-load-the-head-title-in-chrome">http://stackoverflow.com/questions/2911930/jquery-cant-load-the-head-title-in-chrome
Note: This question is a follow up on the stack overflow question located here: http://stackoverflow.com/questions/2911930/jquery-cant-load-the-head-title-in-chrome
推荐答案
这是网址:/用户/最近/ 205784
这将是标题:用户antimatter15 - 最近 - 堆栈溢出
这是网址:/约
这将是标题:关于 - 堆栈溢出
这是网址:/ FAQ
这将是标题:常见问题 - 堆栈溢出
这是网址:/用户/ 205784 / antimatter15
This is the url: /users/recent/205784
This would be the title: User antimatter15 - Recent - Stack Overflow
This is the url: /about
This would be the title: About - Stack Overflow
This is the url: /faq
This would be the title: FAQ - Stack Overflow
This is the url: /users/205784/antimatter15
您code似乎工作。难道说该链接是出了当前域和违反同源策略?
Your code seems to work. Could it be that the links are out of the current domain and violating the same-origin-policy?
这篇关于使用Javascript / jQuery的$。获得(URL)名称解析无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!