通过iframe 异步加载script

  通过异步请求另一页面的script 是不执行的,只返回html 原文件,因为返回的文本没有经过浏览器的解析执行。

 看代码

 a1.html

代码
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
</head>
<script type="text/javascript">
function testClick()
{
document.getElementById(
"tsrc").src="a2.html"
}
</script>
<body>
<div style="display:none"><iframe id="tsrc"></iframe></div>
<input id="Button1" type="button" value="异步加载script" onclick="testClick()"/>
</body>
</html>

a2.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
</head>
<body>
<script>
alert(
'我是异步script');
</script>
</body>
</html>

相关文章:

  • 2021-11-14
  • 2021-10-10
  • 2021-06-12
  • 2022-12-23
  • 2021-08-28
  • 2022-12-23
  • 2022-02-07
猜你喜欢
  • 2022-01-05
  • 2021-07-20
  • 2021-06-16
  • 2021-11-09
相关资源
相似解决方案