新人求助,代码运行错误!
隐藏左侧框架,运行不了,求助前辈解决!
HTML之实现可隐藏式导航栏.zip
(2.26 KB)
index.html页面:
程序代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>框架的属性</title> </head> <frameset id="myset" cols="150px, *"> <frame src="nav.html" name="leftFrame" scrolling="yes" noresize="noresize" /> <frameset rows="40px, *"> <frame src="tool.html" name="topFrame" scrolling="no" noresize="noresize" /> <frame src="content.html" name="mainFrame" scrolling="auto" noresize="noresize" /> </frameset> </frameset> </html>
tool.html页面:
程序代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>工具框架</title> <script> function hideOrDisplayNavFrame() { var frameset = window.self.top.document.getElementById("myset"); var button = window.self.document.getElementById("mybtn"); if (button.value == "隐藏导航栏") { frameset.cols = "0px, *"; button.value = "显示导航栏"; } else { frameset.cols = "150px, *"; button.value = "隐藏导航栏"; } } </script> </head> <body> <input id="mybtn" type="button" value="隐藏导航栏" onclick="hideOrDisplayNavFrame();" /> </body> </html>
运行时总提示下面错误:
ol.html:9 Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame.
at hideOrDisplayNavFrame (file:///C:/Users/admin/Documents/%E6%9C%AA%E5%91%BD%E5%90%8D%E7%AB%99%E7%82%B9%205/tool.html:9:44)
at HTMLInputElement.onclick (file:///C:/Users/admin/Documents/%E6%9C%AA%E5%91%BD%E5%90%8D%E7%AB%99%E7%82%B9%205/tool.html:25:88)
at hideOrDisplayNavFrame (file:///C:/Users/admin/Documents/%E6%9C%AA%E5%91%BD%E5%90%8D%E7%AB%99%E7%82%B9%205/tool.html:9:44)
at HTMLInputElement.onclick (file:///C:/Users/admin/Documents/%E6%9C%AA%E5%91%BD%E5%90%8D%E7%AB%99%E7%82%B9%205/tool.html:25:88)
[此贴子已经被作者于2023-6-1 10:28编辑过]