0

I'm designing a website, in which there's a navigation bar on top, and an iFrame below it. What I'm trying to do is, the user will navigate through out the website within this iFrame. And the nav bar will be there on the top, the whole time. Currently, my nav bar links open a document in my iFrame like this:

<li class="nav-top-links"><a class="a-nav-top-links" href="sample1.html" target="tFrame">ITEM1</a></li>

What I want to know is:

  1. How can I change the URL in the browser, based on the link of the opened page in the iFrame? Is there any kind of 'listener' that I can implement? All pages will be of same domain.

  2. Would someone like to advise on any better approach?

AnkitNeo
  • 122
  • 9

2 Answers2

0

You can pass messages between an iframe and the parent document. Check out this answer for details: make iframe height dynamic based on content inside- JQUERY/Javascript

Community
  • 1
  • 1
Marty Mulligan
  • 994
  • 6
  • 8
0

You might try pushState or Hash key navigation.

pushState example:

var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "bar.html");

Hash Key example:

if ("onhashchange" in window) {  
  alert("The browser supports the hashchange event!");  
}  

function locationHashChanged() {  
  if (location.hash === "#somecoolfeature") {  
    somecoolfeature();  
  }  
}  

window.onhashchange = locationHashChanged;

Related topics:

Display iFrame url in address bar

Change the URL in the browser without loading the new page using JavaScript

Changing address bar when using iframe

Community
  • 1
  • 1