在 www.example.com/page_a/ 上是否可以运行 javascript 代码来搜索位于 www.example.com/page_b 的文件内的文本“hello”/my_file.txt ?
这对 javascript/jquery/任何其他 javascript 框架是否可行?
最佳答案
是的,这是可能的,而且使用 jquery 最简单。
您需要像这样“获取”文本文件的内容:
$.get("www.example.com/page_b/my_file.txt", function(contents){
//contents variable now contains the contents of the textfile as string
//check if file contains the word Hello
var hasString = contents.includes("Hello");
//outputs true if contained, else false
console.log(hasString);
})
关于javascript - 使用javascript在文本文件中搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39996539/