How do I change the URL of the "parent" frame?

ubiquibacon picture ubiquibacon · Dec 5, 2010 · Viewed 25.1k times · Source

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.

Answer

The Scrum Meister picture The Scrum Meister · Dec 5, 2010

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