1、 不能跨域,如果跨域请配置代理或nginx,必须同源
'/restcloud': {target: 'http://10.1.17.210:8080',changeOrigin: true,pathRewrite: {'^/restcloud': '/restcloud', // 这里可以省略,因为路径是一样的}}
或者
server {listen 8090;server_name localhost;location / {proxy_pass http://localhost:9103; 本地项目运行地址}location /restcloud/ {proxy_pass http://*************/restcloud/; 代理的目标地址}location /res/ {proxy_pass http://10.1.17.210:8080/res/; 代理的目标资源文件 我这边资源请求前缀是/res/}
2、操作
const iframe = document.getElementById("myIframe");iframe.onload = function () {const iframeDocument = iframe.contentDocument;var dom1 = iframeDocument.getElementsByClassName("monitorlogo-w")[0];var dom2 = iframeDocument.getElementsByClassName("header-userInfo")[0];//点击dom1.click()//删除操作if (dom1) dom1.remove();if (dom2) dom2.remove();监听子 DOM 节点的变化var content = iframeDocument.getElementById("content");var observer = new MutationObserver(function (mutationsList, observer) {for (var mutation of mutationsList) {if (mutation.type === "childList") {let dom1 =iframeDocument.getElementsByClassName("monitorlogo-w")[0];let dom2 =iframeDocument.getElementsByClassName("header-userInfo")[0];var dom3List = iframeDocument.getElementsByClassName("header-content-right")[0].children;if (dom1) dom1.remove();if (dom2) dom2.remove();
//header-content-right的直接子节点中没有类名的 <span> 节点if (dom3List)for (var i = 0; i < dom3List.length; i++) {var child = dom3List[i];if (child.tagName.toLowerCase() === "span" &&!child.className) {child.remove();}}}}});// 配置观察选项var config = {childList: true, // 观察子节点的添加和删除attributes: true, // 观察属性的变化subtree: true, // 观察所有子节点};// 开始观察if (content) {observer.observe(content, config);}};