如何更改“父级”的 URL框架?

发布于 2024-10-05 19:28:30 字数 1537 浏览 0 评论 0原文

我有一个自己托管的网站。我没有静态 IP 地址,因此我的域的所有流量都通过屏蔽转发到我的 DDNS 帐户。结果页面如下所示...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>mydomianname.com</title>
</head>
<frameset rows="100%,*" border="0">
  <frame src="http://myddns.dyndns.org/mydomainname" frameborder="0" />
  <frame frameborder="0" noresize />
</frameset>
</html>

当用户在“子”框架内导航时,如何更新“父”框架的 URL?

更新:成功?

我曾尝试使用 javascript 执行此操作,但在为我的 javascript 函数获取正确的 href 时遇到问题,并且不会产生不利的副作用(打开两个窗口,让我的主窗口转到错误的位置,或者使其后退按钮无法正常工作)。我所需要的只是 a 标记的一个属性来保存一个可以在 javascript 中使用的值,但不会执行任何其他操作。添加属性 value 事件虽然不是 a 标记的本机属性,但效果很好。

a 标签...

<a onclick="url_update(this);" value="test/test.html" href="javascript:void(0);">test link</a>

和 ​​javascript 函数...

function url_update(element){
    base_url = 'http://mydomain.com/';
    window.parent.location.href = base_url + element.getAttribute('value');
}

更新后的 URL 是...

http://mydomain.com/test/test.html

...并且没有前面提到的副作用。

我想修复的唯一“副作用”是在浏览器窗口底部的信息栏中显示链接。现在它显示 javascript:void(0); 因为这是我的 href 属性中写入的内容,但我希望它在链接悬停时显示更新的 URL...有什么想法吗?

如果我可以放弃所有这些 javascript 并使用 IIS 7 URL Rewrite 2.0 来完成此操作,那就更好了...但我还没有掌握 URL 重写的黑魔法。

I have a website which I host myself. I do not have a static IP address so I have all traffic for my domain forwarded with masking to my DDNS account. The resulting page looks like this...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>mydomianname.com</title>
</head>
<frameset rows="100%,*" border="0">
  <frame src="http://myddns.dyndns.org/mydomainname" frameborder="0" />
  <frame frameborder="0" noresize />
</frameset>
</html>

How can I update the URL of the "parent" frame as users navigate within the "child" frame?

UPDATE: Success?

I have tried doing this with javascript but had an issue getting the correct href to my javascript function with out having adverse side effects (having two windows open up, having my main window go to the wrong location, or making it so the back button didn't work right). All I needed was an attribute of my a tag to hold a value that I could use in my javascript, but would do nothing else at all. Adding the attributed value event though it is not a native attribute to the a tag works great.

The a tag...

<a onclick="url_update(this);" value="test/test.html" href="javascript:void(0);">test link</a>

and the javascript function...

function url_update(element){
    base_url = 'http://mydomain.com/';
    window.parent.location.href = base_url + element.getAttribute('value');
}

the resulting updated URL is...

http://mydomain.com/test/test.html

... and there are none of the previously mentioned side effects.

The only "side effect" that I would like to fix is display of the link in the info bar at the bottom of a browser window. Right now it says javascript:void(0); because that is what is written in my href attribute, but I would like it to show the updated URL when the link is hovered over... any thoughts?

It would be even better if I could scrap all of this javascript and use IIS 7 URL Rewrite 2.0 to do this instead... but I have yet to master the black art of URL rewriting.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冬天旳寂寞 2024-10-12 19:28:30

javascript:

window.top.location = 'anther url'

--更新您更新的问题

使用 element.getAttribute('value') 而不是 element.value

--UPDATE #2
但是,请使用 href 属性,将 return false; 添加到 onclick 函数:

<a onclick="url_update(this);return false;" value="test/test.html" href="test/test.html">test link</a>

一旦执行此操作,您也可以跳过 value 属性并仅使用 href 属性,更新您的 url_update 函数以使用element.href 而不是 element.value

javascript:

window.top.location = 'anther url'

--UPDATE to your updated question

use element.getAttribute('value') instead of element.value

--UPDATE #2
Use the href attribute, however, add a return false; to the onclick function:

<a onclick="url_update(this);return false;" value="test/test.html" href="test/test.html">test link</a>

Once you are doing that, you might aswell skip the value attribute and just use the href property, update your url_update function to use element.href instead of element.value

緦唸λ蓇 2024-10-12 19:28:30

很难从你的问题中准确判断哪些框架在做什么,但如果 Scrum Meister 的解决方案适合你,那么你可以通过将其添加到每个 A 标签来轻松实现你想要的功能。

 target="_top"

你的例子修改了。

<a href="test/test.html" target="_top">test link</a> 

你也可以用 jquery 来做到这一点......
在所有A标签都应该有target =“_top”的页面上,您可以在页面上实现以下jquery代码,它将动态地将目标添加到所有链接。

<script language="javascript" type="text/javascript">
$(function()
{
     $("A").attr("target","_top");
});
</script>

假设您有带有 href 属性的normail A 标记,您可以一起摆脱 onclick,目标解决方案不需要其他 javascript。

It's hard to tell from your question exactly which frames are doing what, but if The Scrum Meister's solution works for you, than you can easily implement what you want by adding this to each of your A tags.

 target="_top"

Your example modified.

<a href="test/test.html" target="_top">test link</a> 

You could also do this with jquery...
On the page where all A tags should have target="_top" you can implement the following jquery code on the page and it will dynamically add the target to all links.

<script language="javascript" type="text/javascript">
$(function()
{
     $("A").attr("target","_top");
});
</script>

That is assuming that you have normail A tags with the href attribute, you can get rid of the onclick all together, no other javascript is required with the target solution.

野稚 2024-10-12 19:28:30

首先,您需要位于同一个域中...否则出于安全原因您无法更改它。
在您的子框架中声明并调用此函数

function change(theUrl){

window.parent.reloadContent(theUrl);
}

在您的父框架中有以下函数:

function reloadContent(theUrl){
  if (theUrl != ""){ 
      document.getElementById("frameID").src= theUrl ; 
  } 
}

First you need to be on the same domain... otherwise for security reasons you can not change it.
Declare and call this function in your child frame

function change(theUrl){

window.parent.reloadContent(theUrl);
}

In your parent have the following function :

function reloadContent(theUrl){
  if (theUrl != ""){ 
      document.getElementById("frameID").src= theUrl ; 
  } 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文