增加与iframe的事件通信 #46

Merged
yezian merged 1 commits from main into space_domain 2025-03-17 19:44:42 +08:00
1 changed files with 19 additions and 3 deletions
Showing only changes of commit 5b3e196859 - Show all commits

View File

@ -1,12 +1,28 @@
"use client";
import React from "react";
import React, { useEffect } from "react";
import { useRouter, useParams } from "next/navigation";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faAngleLeft } from "@fortawesome/free-solid-svg-icons";
export default function WebView() {
const { src } = useParams();
const router = useRouter();
useEffect(() => {
// 添加消息事件监听器
const handleMessage = (event) => {
if (event.data && event.data.type === "navigation" && event.data.url) {
router.push(event.data.url);
}
};
window.addEventListener("message", handleMessage);
// 清理函数
return () => {
window.removeEventListener("message", handleMessage);
};
}, [router]);
return (
<div>
{/* <div className="p-4 fixed top-0 z-10 w-full">