Get current page URL and title with jQuery

Get current page URL and title with jQuery

by Jennifer Perrin

HTML

<p>Current page URL: <span id="current_url">www.example.com</span>.</p>
<p>Current page title: <span id="current_title">mytitle</span>.</p>

JavaScript

jQuery(document).ready(function() {
    var href = jQuery(location).attr('href');
    var url = jQuery(this).attr('title');
    jQuery('#current_title').html(href);
    jQuery('#current_url').html(url);
});