在www.example.com/page_a/上是否可以运行JavaScript代码来搜索位于www.example.com/page_b/my_file.txt的文件内的文本“ hello” ?
使用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);
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2520 次 |
| 最近记录: |