[英]Inject local HTML file into webpage via Chrome Extension using iframe?
I have a HTML file that I want to inject next to each result of a Google search result page from a Chrome extension. 我有一个HTML文件,我想在Chrome扩展程序的Google搜索结果页面的每个结果旁边注入该文件。
I was wondering if I could use an iframe to load the HTML file? 我想知道我是否可以使用iframe加载HTML文件?
This is instead of my current implementation that uses insertAdjacentHTML()
in my Content Script and a horrible long string of HTML and inline CSS. 这不是我当前在我的内容脚本中使用insertAdjacentHTML()
实现, insertAdjacentHTML()
一个可怕的长串HTML和内联CSS。 Would much prefer to have a separate HTML file with its own CSS that I can just insert instead. 更愿意有一个单独的HTML文件,它有自己的CSS,我可以插入。
I tried: 我试过了:
chosenElements[i].insertAdjacentHTML('afterbegin', `<iframe src="/inject.html"></iframe>`);
but just get an iframe with a 404 page because it is looking in the ' https://www.google.com/index.html ' directory rather than where the file sits. 但只是获得一个404页面的iframe,因为它正在查看“ https://www.google.com/index.html ”目录,而不是文件所在的位置。
The inject.html file is in the same place as the index.html file in my build folder for the extension. inject.html文件与扩展的build文件夹中的index.html文件位于同一位置。 How do I access it? 我该如何访问它? Can I access it? 我可以访问它吗?
Have you tried with 你试过吗?
src="inject.html"
instead of 代替
src="/inject.html"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.