调用iframe中方法的方法
代码简单,一看就会:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<iframe src="./test2.html" frameborder="0" id="iframeDOM"></iframe>
<script>
setTimeout(() => {
const iframeWindow = document.getElementById("iframeDOM").contentWindow.window.methods;
iframeWindow.changeText();
}, 1000)
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="hello">Hello World!</div>
<script>
const hello = document.querySelector(".hello");
window.methods = {
changeText: () => {
hello.innerHTML = "Hello Vue!";
}
}
</script>
</body>
</html>