Posted By

vjandrei on 05/08/12


Tagged

jquery


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

hurcy


Get current page URL and title with jQuery


 / Published in: JavaScript
 

  1. <p>Current page URL: <span id="this_url">www.example.com</span>.</p>
  2. <p>Current page title: <span id="this_title">mytitle</span>.</p>
  3.  
  4. <script type="text/javascript">
  5. jQuery(document).ready(function () {
  6. var href = jQuery(location).attr('href');
  7. var url = jQuery(this).attr('title');
  8. jQuery('#this_title').html('<strong>' + href + '</strong>');
  9. jQuery('#this_url').html('<strong>' + url + '</strong>');
  10. });
  11. </script>

Report this snippet  

You need to login to post a comment.