javascript - php 包括,通过 javascript 替代 - 网络和科尔多瓦测试
问题描述
为我和后代保存
这是通过 javascript 创建的替代包含。我在cordova(网络和安卓)上进行了测试和工作。
function jsinclude()
{
let x, i, el, file, request;
/*loop all doc el*/
x = document.getElementsByTagName("*");
for (i = 0; i < x.length; i++)
{
el = x[i]; //el by el
file = el.getAttribute("include"); //get path
if (file)
{
//check the path error
if (file.startsWith("/") )
{
alert("\n\nerror in file path: do not use the ' / ' as initial.\n\n\Follow the example below:\n<div include='myfolder/.../file.html'></div>\n\n");
let mex = '<p style="backraound:white !important; padding:20px !important; border: 1px solid red !important; color:red !important; font-weight:bold !important;"> !! ERROR: WRONG PATH FOR INCLUDE</p>';
el.innerHTML = mex;
};
//create HTTP request
request = new XMLHttpRequest();
request.onload = function ()
//request.onreadystatechange = function () //simple alternative
{
if (this.status == 200 ) // if ok
{
console.log("include-js: inlcude file: " + file +" | rquest status: "+this.status+" | data printed: "+this.responseText);
el.innerHTML = this.responseText;
}
else if (this.status == 404) // if ok... but not found
{
alert("error in file path or server:\n404 file not founded.");
}
else if (this.status != (404 && 0 && 200)) // if... wtf!??
{
alert("undefined server error on include js");
}
// stop and repeat
el.removeAttribute("include");
jsinclude();
}
// sand all... and exit
request.open("GET", file, true);
request.send();
return;
}
}
};
身体内的每个标签都可以完美运行。
<body>
<div include="yourpath/test.html">
included html content ;)
</div>
</body>
阅读注释以包含头部内容
<head include="yourpath/head meta etc.html">
content loaded... (read note)
</head>
注意:我还没有测试,在包含头部之后,它是否会继续阻止头部标签内的其他脚本(目前)。
解决方案
推荐阅读
- c++ - 如何使用 gcc 通过命令行限制 C++ 代码的内存使用量?
- r - R:pmax() 函数忽略 NA 的?
- spring-mvc - Spring项目包需要解决的问题
- python - Python从正态分布生成随机麦克斯韦分布
- python - 在 Python 中使用记录器模块 - 无法同时记录控制台和文件
- android - 如何更改 Dialog 窗口大小 Android studio
- java - java中的Ludo板
- gnuplot - 如何为 gnuplot 箱形图使用调色板索引?
- java - 如何从java中的用户输入中获取时间格式?
- c# - 从 Entity Framework Core 获取错误列表包含另一个列表