How to get current html page title with javascript

后端 未结 4 911
予麋鹿
予麋鹿 2020-12-03 06:17

I\'m trying to get the plain html page title with javascript.

I use firefox and with

document.title 

I get extra \"- Mozilla Firef

相关标签:
4条回答
  • 2020-12-03 06:49

    try like this

    $('title').text();
    
    0 讨论(0)
  • 2020-12-03 06:50

    One option from DOM directly:

    $(document).find("title").text();
    

    Tested only on chrome & IE9, but logically should work on all browsers.

    Or more generic

    var title = document.getElementsByTagName("title")[0].innerHTML;
    
    0 讨论(0)
  • 2020-12-03 06:54

    Like this :

    jQuery(document).ready(function () {
        var title = jQuery(this).attr('title');
    });
    

    works for IE, Firefox and Chrome.

    0 讨论(0)
  • 2020-12-03 07:00
    $('title').text();
    

    returns all the title

    but if you just want the page title then use

    document.title
    
    0 讨论(0)
提交回复
热议问题