How do I change the URL of the “parent” frame?

徘徊边缘 提交于 2019-12-05 11:03:16

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

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.

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 ; 
  } 
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!