Search code examples
javascriptwidgetbloggerblogspot

How can I know if the current opened page is a post page and not category or archive page using javascript?


I'm creating a gadjet for Blogger(blogspot), this widget will be placed on all pages(post,archive and coutegory pages) but I need to get the url of the current opened post only(not category page, not archive page not any other kind of pages).

I only use javascript code in my gadjet so I need to do that in JS.

In other words how can I know if the current page is post page?


Solution

  • You can some information about the current page on the location global variable:

    >>> location.href
    "http://stackoverflow.com/questions/8288422/how-can-i-know-if-the-current-opened-page-is-a-post-page-and-not-category-or-arc/8288481#8288481"
    >>> location.pathname
    "/questions/8288422/how-can-i-know-if-the-current-opened-page-is-a-post-page-and-not-category-or-arc/8288481"