Take the 2-minute tour ×

Even though the following works: http://jsfiddle.net/N7D5r/

My attempt at using the same code does not correctly get the titles. They return null, for whatever strange reason:

<script type="text/javascript">
    // Act on each link

        // Store current link's url

        $.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]);
                alert("title was null");


<p><a href="javascript:;">Javascript link</a></p>
<p>&nbsp;<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>

Any Ideas?

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

share|improve this question
How does it not work? What does the whole "response" look like? Does the code say that the title is null, or does it give the wrong result? –  Pointy May 26 '10 at 18:55
This code works for me, just pasted into a new HTML page. Are you trying to run it locally? If so you may need to allow it to access the external content. –  Shawn Steward May 26 '10 at 18:58
By it not working, what I mean is that it isn't getting the titles from the links. It's running "Title was null" even when the url does have a title. –  Matrym May 26 '10 at 19:03
This worked for me in IE8 but didn't work in Chrome, so not sure if you have a compatibility issue here or not. –  Shawn Steward May 26 '10 at 19:10

1 Answer 1

up vote 1 down vote accepted

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

Your code seems to work. Could it be that the links are out of the current domain and violating the same-origin-policy?

share|improve this answer
Same domain, as tested here: latentmotion.com/bookmarklets/link-checker/test.html –  Matrym May 26 '10 at 19:07
DOH! It was a no www subdomain issue I think. –  Matrym May 26 '10 at 19:07

Your Answer


