The Moz Q&A Forum

    • Forum
    • Questions
    • My Q&A
    • Users
    • Ask the Community

    Welcome to the Q&A Forum

    Browse the forum for helpful insights and fresh discussions about all things SEO.

    1. SEO and Digital Marketing Q&A Forum
    2. Categories
    3. Intermediate & Advanced SEO
    4. Javascript to fetch page title for every webpage, is it good?

    Javascript to fetch page title for every webpage, is it good?

    Intermediate & Advanced SEO
    6 4 2.1k
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as question
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • SmartStartMediacom
      SmartStartMediacom last edited by

      We have a zend framework that is complex to program if you ask me, and since we have 20k+ pages that we need to get proper titles to and meta descriptions, i need to ask if we use Javascript to handle page titles (basically the previously programming team had NOT set page titles at all) and i need to get proper page titles from a h1 tag within the page.

      current course of action which we can easily implement is fetch page title from that h1 tag being used throughout all pages with the help of javascript, But this does makes it difficult for engines to actually read what's the page title? since its being fetched with javascript code that we have put in, though i had doubts, is anyone one of you have simiilar situation before? if yes i need some help!

      Update: I tried the JavaScript way and here is what it looks like http://islamicencyclopedia.org/public/index/hadith/id/1/book_id/106  i know the fact that google won't read JavaScript like the way we have done with the website, But i need help on "How we can work around this issue"  Knowing we don't have other options.

      1 Reply Last reply Reply Quote 0
      • DanielMulderNL
        DanielMulderNL last edited by

        Hi... I would not prefer a client side approach to this. If it's readable depends on the script itself. Although some JS fans will say this alright I would prefer to do this server side with php, or similar, and make a template that does this rewrite. It's not to hard. Or why not a batch run to modify all pages once to hardcode the correct title in the page? Have some scripts that can do this for you if you would like.

        Hope this helps.

        SmartStartMediacom 1 Reply Last reply Reply Quote 1
        • SmartStartMediacom
          SmartStartMediacom @DanielMulderNL last edited by

          Thank you Daniel for the input, Since the code is all messed up and i can't convince the Board to redo the site from scratch. i'll have to go with small tricks with title tags and descriptions to be set, with JavaScript as i just tried, it worked and it now does fetch all the titles and displays them on the browser title, without any significant change in the actual code except for the addition of JavaScript that i just tried.

          But i did a test run with Rich snippet testing tool to see what Google pulls in as preview for search results, and it didn't show anything, No title and No description .. alas! So i guess it does mean using JavaScript to fetch title & description won't help? I'm still not sure.

          So now the real question i have in mind; Does this Javascript technique that we just used, will it be of any good SEO wise or will have any value?

          DanielMulderNL 1 Reply Last reply Reply Quote 1
          • Er_Maqui
            Er_Maqui last edited by

            Any javascript effor is invalid for SEO. Google doesn't read them.

            You can try to make it on PHP, it's not complex, search your an replace with meta desc=$var and <title>$var2 (and, also, </head>). Then you can set the meta desc and page title with a variable in your code, and then this effor effectively have SEO value, because when the search engine fetch the page they have title and desc.</p> <p>Maybe this is more work than JS form, but also it's better for SEO and web itself (The JS run takes time on client side).</p></title>

            1 Reply Last reply Reply Quote 1
            • David-Kley
              David-Kley last edited by

              Google can read Javascript, but only certain types and implemetations. Is there a way you can set this swap out to happen on the database or server side? That might be the best way to get the live text readable, as most likely the javascript is being rendered and displayed after the initial crawl of the page. Even if it is a milisecond later, Google might not allow/catch it.

              1 Reply Last reply Reply Quote 2
              • DanielMulderNL
                DanielMulderNL @SmartStartMediacom last edited by

                Your welcome. Interesting question. My answer is that if the HTML TITLE is set with client side JavaScript then it's has little change of being picked up as the title by crawlers or Google. Let's say we alter the node element Title value with like this:

                In this case it will alter the value after the hard coded HTML title was send to the browser. It would need the crawler to load the document in full and read the HTML title value only after fully rendering it as if it where a human user. This is not likely.

                Then we could also try a document write to construct the HTML HEAD tag Title as a string to use for the browser as the title like this:

                Will not work as the title text is not actually altered after evaluation of the script line.

                This does not work because the title is not set but because it's not actually printed to the browser as a string. The source code for the title still looks like this in to any browser:

                As you can see the script does not print the result string of the evaluation to the browser but still sets the value of the document object model node HTML TITLE to the value it evaluates to.

                Try it for yourself with this dummy page I made just to be certain.
                http://www.googlewiki.nl/test/seojavascripttest2.html And this is the DOM info for this page http://www.googlewiki.nl/seo-checker/testanchor.php?url=http://www.googlewiki.nl/test/seojavascripttest2.html&anchor=test

                Or am I missing something here?

                Hope this helps.

                1 Reply Last reply Reply Quote 1
                • 1 / 1
                • First post
                  Last post
                • After adding a ssl certificate to my site I encountered problems with duplicate pages and page titles
                  LovingatYourBest
                  LovingatYourBest
                  0
                  4
                  168

                • On 1 of our sites we have our Company name in the H1 on our other site we have the page title in our H1 - does anyone have any advise about the best information to have in the H1, H2 and Page Tile
                  Kenn_Gold
                  Kenn_Gold
                  0
                  5
                  601

                • Is a different location in page title, h1 title, and meta description enough to avoid Duplicate Content concern?
                  couponguy
                  couponguy
                  0
                  3
                  199

                • Should We Add the W3.org Language Tag To Every Page Or Just The Home Page?
                  gfiorelli1
                  gfiorelli1
                  0
                  4
                  101

                • Merge content pages together to get one deep high quality content page - good or not !?
                  lewislove
                  lewislove
                  0
                  3
                  155

                • Duplicate Page Title/Content Issues on Product Review Submission Pages
                  PartyStore
                  PartyStore
                  0
                  7
                  747

                • How do I fix the error duplicate page content and duplicate page title?
                  rtavs
                  rtavs
                  0
                  4
                  467

                • Page titles
                  wazza1985
                  wazza1985
                  0
                  3
                  957

                Get started with Moz Pro!

                Unlock the power of advanced SEO tools and data-driven insights.

                Start my free trial
                Products
                • Moz Pro
                • Moz Local
                • Moz API
                • Moz Data
                • STAT
                • Product Updates
                Moz Solutions
                • SMB Solutions
                • Agency Solutions
                • Enterprise Solutions
                • Digital Marketers
                Free SEO Tools
                • Domain Authority Checker
                • Link Explorer
                • Keyword Explorer
                • Competitive Research
                • Brand Authority Checker
                • Local Citation Checker
                • MozBar Extension
                • MozCast
                Resources
                • Blog
                • SEO Learning Center
                • Help Hub
                • Beginner's Guide to SEO
                • How-to Guides
                • Moz Academy
                • API Docs
                About Moz
                • About
                • Team
                • Careers
                • Contact
                Why Moz
                • Case Studies
                • Testimonials
                Get Involved
                • Become an Affiliate
                • MozCon
                • Webinars
                • Practical Marketer Series
                • MozPod
                Connect with us

                Contact the Help team

                Join our newsletter
                Moz logo
                © 2021 - 2026 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
                • Accessibility
                • Terms of Use
                • Privacy