简体   繁体   English

Javascript:如何在启动前检查要启动的网址是否存在?

[英]Javascript: How can I check to see if url to fire exists before firing it?

I am getting urls from a feed that I assign to list of buttons, some of the urls produce 404s when clicked on said buttons. 我从分配给按钮列表的摘要中获取了url,单击这些按钮时,某些url会产生404。 Is there a way to check if the landing page exists first before I fire it? 有没有一种方法可以在我触发目标网页之前先检查目标网页是否存在?

Some of these urls have tracking pixels in them to know when they are clicked so I wouldn't want to fire it in an iframe or a similar solution as it would possibly track twice to test if it exist first before it fires. 其中一些网址中包含跟踪像素,以了解何时单击它们,因此我不想在iframe或类似的解决方案中将其触发,因为它可能会跟踪两次以测试它在触发之前是否首先存在。

Is this even possible? 这有可能吗? The domains will not be the same and I can't use jQuery. 域将是不同的,并且我不能使用jQuery。

To test an url you must access it. 要测试网址,您必须访问它。 So, without an external service, you can't test them beforehand. 因此,没有外部服务,您将无法事先对其进行测试。

W3C provides a link checker: https://validator.w3.org/checklink "The program can be used either as a command line tool or as a CGI script." W3C提供了一个链接检查器: https : //validator.w3.org/checklink “该程序既可以用作命令行工具,也可以用作CGI脚本。” Maybe you can use it to test an url and, after, create or not your button. 也许您可以使用它来测试url,然后再创建或不创建按钮。

I don't know if there is a limit for this service, so check the documentation! 我不知道此服务是否有限制,请查看文档! http://search.cpan.org/dist/W3C-LinkChecker/bin/checklink.pod http://search.cpan.org/dist/W3C-LinkChecker/bin/checklink.pod

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM