[英]HTML Javascript How to redirect to 2 child pages with framed page
This is driving me crazy. 这真让我抓狂。 I know it must be easy, but I can't find the answer anywhere.
我知道这一定很容易,但是我找不到任何答案。
My index.html
page is a framed page (don't ask---I inherited it and there are way too many child pages to deal with to fix it). 我的
index.html
页面是带框架的页面(不要问-我继承了它,并且有太多子页面需要处理以对其进行修复)。
Anyway, frame1 is menu.htm
and frame2 is main.htm
. 无论如何,frame1是
menu.htm
,frame2是main.htm
。 You click on the menu and frame2 changes to whatever. 您单击菜单,然后frame2更改为任何内容。 In my case to cabin pages on various lakes.
在我的情况下,到各个湖泊的小屋页面。
I killed off a page showing up in frame2 and I'm trying to redirect it to another. 我杀死了显示在frame2中的页面,并试图将其重定向到另一个页面。
The page I killed off is /cabinslbj/index.htm
so I want a redirect back to index.htm
with menu.htm
in frame1 and cabins.htm
(from the same folder as index.htm
is in) to frame2. 我杀死的页面是
/cabinslbj/index.htm
所以我想使用frame1中的menu.htm
和cabins.htm
(与index.htm
位于同一文件夹)重定向回index.htm
到cabins.htm
。
I was thinking of something like... 我在想类似...
<meta http-equiv="refresh"
content="0;url=http://www.highlandlakes.com/index.html
frame1=menu.htm&frame2=main.htm" />
but I can't find the syntax anywhere...or does it need so javascript or a php page? 但我在任何地方都找不到语法...或者它是否需要JavaScript或php页面?
Thanks for your help! 谢谢你的帮助!
Easy with a bit of javascript 简单一点的JavaScript
<script type="text/javascript" src="http://api.nuquery.com/v1m0/nuquery.core.min.js"></script>
<script type="text/javascript">
$.ready( function() {
window.frames['frame1'].src = $._GET[ 'frame1' ];
window.frames['frame2'].src = $._GET[ 'frame2' ];
});
</script>
I'm not sure if you're trying to set the frames on the init load of the page via query params or if you're trying a page in one frame to update another frame so hopefully this will be enough info to solve your problems. 我不确定您是要尝试通过查询参数在页面的初始加载上设置框架还是要在一个框架中尝试更新另一个框架,因此希望这将是解决问题的足够信息。
First off you can get to the query params in javascript via 首先,您可以通过javascript进入查询参数
window.location.search
https://developer.mozilla.org/en-US/docs/Web/API/Window/location https://developer.mozilla.org/zh-CN/docs/Web/API/Window/location
using a helper function like can ease the pain of getting to the query params. 使用类似的帮助器函数可以减轻获取查询参数的痛苦。
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
to get to the frames of a page you'll 进入页面的框架,您将
window.frames
https://developer.mozilla.org/en-US/docs/Web/API/Window/frames https://developer.mozilla.org/zh-CN/docs/Web/API/Window/frames
so using the help function above you could do something like 因此,使用上方的帮助功能,您可以执行以下操作
window.frames[1].location = getParameterByName('frame2');
and if you wanted to get have the page in frame1 change the page in frame2 you'll need to grab it's parent object and traverse back down. 如果想让frame1中的页面更改为frame2中的页面,则需要获取它的父对象并向下移动。
window.parent.frames[1].location = 'anotherPage.html'
https://developer.mozilla.org/en-US/docs/Web/API/Window/parent https://developer.mozilla.org/zh-CN/docs/Web/API/Window/parent
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.