如果我通过 JavaScript 在页面中添加内容,搜索引擎蜘蛛是否可以抓取该内容

发布于 2024-09-07 04:35:34 字数 930 浏览 13 评论 0原文

如果我通过 JavaScript 在页面中添加内容,搜索引擎蜘蛛可以抓取该内容并可以通过屏幕阅读器访问。

对于 示例

var tip = "<p>Most computers will open PDF documents ";
tip += "automatically, but you may";
tip += "need to download <a title='Link to Adobe website-opens in a new window'";
tip +=" href='http://www.adobe.com/products/acrobat/readstep2.html'  
               target='_blank'>Adobe Reader</a>.</p>";

$(document).ready(function(){

    //IF NUMBER OF PDF LINKS IS MORE THAN ZERO INSIDE DIV WITH ID maincontent
    //THEN THIS WILL PUT TIP PARAGRAPH AS LAST CHILD OF DIV
    if($("div#maincontent a[href*='/pdf']").length>0){
    $("div#maincontent").children(":last-child").after(tip);
    }
});

编辑:我想向搜索引擎隐藏此内容,但同时保持屏幕阅读器可访问,这可能吗?

If I'm adding content in page through JavaScript will it be crawl-able by Search engine spider and accessible by screen reader.

For example this

var tip = "<p>Most computers will open PDF documents ";
tip += "automatically, but you may";
tip += "need to download <a title='Link to Adobe website-opens in a new window'";
tip +=" href='http://www.adobe.com/products/acrobat/readstep2.html'  
               target='_blank'>Adobe Reader</a>.</p>";

$(document).ready(function(){

    //IF NUMBER OF PDF LINKS IS MORE THAN ZERO INSIDE DIV WITH ID maincontent
    //THEN THIS WILL PUT TIP PARAGRAPH AS LAST CHILD OF DIV
    if($("div#maincontent a[href*='/pdf']").length>0){
    $("div#maincontent").children(":last-child").after(tip);
    }
});

Edit: I want to hide this from Search engine but at the same time keep accessible by screen reader is it possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

拧巴小姐 2024-09-14 04:35:34

这取决于爬虫,但不要指望大多数机器人能够解释 Javascript。

It depends on the crawler, but don't expect most bots to interpret Javascript.

屌丝范 2024-09-14 04:35:34

简短的回答,可能不会。但是,Google 一直在变得越来越复杂,所以我怀疑他们实际上将 Javascript 渲染为索引过程的一部分。

这样做有什么特别的原因吗?如果可能的话,我建议在服务器端执行此逻辑,这样您就知道搜索引擎可以读取您的 HTML。

Short answer, probably not. But, Google is getting more sophisticated all the time, so I have my suspicions that they actually render Javascript as part of the indexing process.

Is there a particular reason to do it this way? I'd recommend doing this logic server-side if possible, then you know your HTML is readable by search engines.

于我来说 2024-09-14 04:35:34

回复:动态生成的内容(在浏览器上)可以被搜索引擎抓取吗?

通常情况下,不会。

但谷歌发明了一种方法来解决这个问题。请参阅 ajax 抓取

注意:它们通过使用代表不同查询参数的各种查询参数来抓取您的网址来实现此目的动态页面的状态。他们不会尝试在您的页面上运行 js。

Re: will content generated dynamically (on the browser) be crawlable by a search engine?

Normally, no.

But Google has invented a way to solve the problem. See ajax crawling

Note: they do it by crawling your urls with various query parameters representing the different states of the dynamic page. They do not attempt to run the js on your page.

我们只是彼此的过ke 2024-09-14 04:35:34

不,大多数网络爬虫不执行 JavaScript,旧的屏幕阅读器也不读取它。最好的选择是仅使用 Javascript 进行演示,并使用逻辑服务器端(PHP、Ruby、.NET 等)和一些 CSS 魔法来实现您在上面尝试对内容执行的操作。如果您担心网络爬虫和屏幕阅读器,请始终通过服务器端插入内容,并且仅使用 JavaScript 进行演示。或者,您可以使用屏幕阅读器的 Flash 和 JavaScript 嗅探器将用户重定向到不依赖动态内容的备用页面。

No, most web crawlers do not execute JavaScript and older screen readers do not read it either. Your best bet would be to only use Javascript for presentation purposes and use the logic server side (PHP, Ruby, .NET, etc) and some CSS magic to achieve what you are trying to do above with the content. Always insert content via server side if you are concerned about web crawlers and screen readers, and use JavaScript for presentation only. Alternatively, you can use a Flash and JavaScript sniffer for screen readers to redirect the user to an alternate page that does not rely on dynamic content.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文