Forum Moderators: open

Message Too Old, No Replies

how to write text in javascript

         

alexod

7:03 pm on Jan 24, 2020 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi there,

I need to include text in the footer (sidewide), in order to avoid SEO/duplication issues - I would like to keep that text not indexable for Search both.

So I decided to write text in javascript

 <script>
document.write("text");
</script>


Unfortunately when I'm inspecting the source, or using SE Simulators - this text is visible for Search bots.

1. What I'm doing wrong?
2. As I remember Gbot can't index Js code
3. is there any way to have that text not for Search bots - this is 4 blocks of "SECURITIES DISCLOSURE", which will 100% cause duplication issue for pages with low content.

thanks

NickMNS

9:03 pm on Jan 24, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Whether or not bots see the text has more to do with when it is loaded and not so much how.

Before I explain this in more detail, you should be aware that Googlebot now renders JS content, it typically doesn't occur at the same time as the initial crawl but can occur at a later point when it feeds the previously crawled page to the JS rendering engine. There is no guarantee that Google will ever render your page, so I would be very reluctant to depend on it for index purposes (not what you want anyways) but by the same logic you cannot be sure they won't render the page. If you absolutely do not want Google to see the content then I'm not sure hiding it with delayed JS will work anymore. YMMV.

One should avoid using document.write, it is to be used before the page has loaded. Including it in a script tag will likely cause the page to re-render everything that was on the page up to that point. It will restart loading the page and then in the second go-around include the text. Since your page hadn't fully loaded, Googlebot will be waiting around for page to complete and will then pickup the text that was add. So it will slow the page down considerably and doesn't help you achieve your goal.

What you need to is wait for the page fully load and then insert the text. You could even wait for a user interaction, as there would be no point in loading resources that no one will read.

The easiest way would be something like this:

window.addEventListener('load', function () {
const footer = document.querySelector('footer');
let newText = document.createElement('p');
newText.textContent = "Loreat Ipsum";
footer.appendChild(newText);
})


The above example uses the 'load' event, which means the script will be triggered after the page is fully loaded. To use user interaction as the event, you could use a 'scroll' event, but this will be triggered each time the user scrolls so you'll need to add code to prevent the script from running more that once.

not2easy

2:12 am on Jan 25, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Site elements such as menus, footers and contact/privacy/info that are commonly found of every page of a site are not part of the content that would determine the overall value of a page. Sitewide information in a footer would be better to present normally than in so attempt to be disguised or hidden. It is part of the page and trying to make it only visible to humans could cause you more SEO problems than treating it like any sitewide footer content.

alexod

4:21 pm on Jan 27, 2020 (gmt 0)

10+ Year Member Top Contributors Of The Month



>>>Site elements such as menus, footers and contact/privacy/info that are commonly found of every page of a site are not part of the content that would determine the overall value of a page.

Not2easy, I agree with you when it's regular footer, contact info or sidebar info, but as I said before in this particular case it's a 800 words SECURITIES DISCLOSURE, that by law I need to have on the footer of each page. Some of page on this webiste have less content than this disclosure.

>>>It is part of the page and trying to make it only visible to humans could cause you more SEO problems than treating it like any sitewide footer content.

-
Can you please mention just 1 problem from your experience?

thanks

alexod

4:25 pm on Jan 27, 2020 (gmt 0)

10+ Year Member Top Contributors Of The Month



thanks @NickMNS + ,

One question: How can I format text inside or outside of newText.textContent = "Loreat Ipsum"?
I mean, I need to use the same font fontfamily as on website here , font-size need to be smaller, there is 1 external link , etc ... As I understand there isn't any way to do this.

not2easy

4:33 pm on Jan 27, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Showing text to human visitors and efforts to prevent search engine spiders from seeing that same text is known as "cloaking" and Google says that it is a bad practice: [support.google.com...]

I don't have personal experience with cloaking so I can't be more specific than their own info on this subject.

NickMNS

5:11 pm on Jan 27, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



@alexod the points raised by not2easy are valid, but I think in your case for the purposes of a legal requirement it should not be an issue. I have heard this issue being discussed before in Google's webmaster office hours with John Mueller. Unfortunately it was sometime ago and I don't remember the specifics. It may be worth a search to see how others with this same requirement have handled it.

That said, styling the inserted text is simple. The easiest would be to create a CSS class in your style sheet with the desired styling and then simply add the reference to the element like so:


window.addEventListener('load', function () {
const footer = document.querySelector('footer');
let newText = document.createElement('p');
newText.textContent = "Loreat Ipsum";
newText.className = "my-class"; //<---- my-class is the name of the class added to the CSS style sheet ---//
footer.appendChild(newText);
})


Or you could also change styling by using the .style() method. Personally I find that creating a class is cleaner.
[developer.mozilla.org...]

JorgeV

5:32 pm on Jan 27, 2020 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



Hello-

You can also do something like :
document.getElementById(xxx).InnerHTML="your text with <b>formatting</b>."


If you run it on the onload event, Google (at least) will run it. You can run it on onscroll for example, instead. Or delay it with a timer. If you don't want Robots to load the text, you can also use an external javascript file stored in a folder which is denied in the robots.txt file.

alexod

8:08 pm on Jan 27, 2020 (gmt 0)

10+ Year Member Top Contributors Of The Month



@not2easy,
You right, technically showing something to users and hiding it from SE can be considered as cloaking. (Definition: Cloaking refers to the practice of presenting different content or URLs to human users and search engines.), but at the end that is webmaster's decision to ask

1. Nofollow or nofollow
2. Index or noindex
3. Disallow: (robots.txt)

anything on my site.

There is Zero % to scam SE bots, it's just my decision don't show that content to search engines, or request - don't index that content. I understand that the board is very slicky, and agree with that can be considered as cloaking.

But the same time if I have privacy-policy or thank you page, which is No-index - this can be considered as Cloaking too - text is visible for users, but hidden(or noinxeed) for search engines.

@JorgeV +
I like the idea of external js + Disallow from robots.txt. Thank you.

not2easy

1:22 pm on Jan 28, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



How do your most successful competitors deal with the requirement to show those blocks of Securities Disclosure? I would check there before deciding what works best. ;)

NickMNS

2:56 pm on Jan 28, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I like the idea of external js + Disallow from robots.txt. Thank you.

Storing the text to display in an external js file that is blocked from robots is a good idea. But it is not a solution in and of itself, you still need to manage the timing of when you insert the text onto the page. The reason it is a good idea is that in the case where the text would be included within the page's code (but not visible to users) Googlebot could potentially still see the text and decide that it is relevant. I've seen Googlebot crawl links that were in my js code. Putting the text in a separate file (JSON or other) and blocking it will limit the likelihood of Googlebot seeing/crawling it.

That said, this may be completely moot as I'm guessing that having the text on the page will not cause a problem, and as I mentioned in my first post Google may render the page regardless and see the content. If the content is legal boilerplate it will likely be ignored.

Finally not2easy's advice is very good, go see how your competitors are doing it.

JorgeV

5:05 pm on Jan 28, 2020 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



Hello -again

You can also use an image to represent your text, or/and you can also embed your text into an SVG file.