Jump to content

Frameset Redirect


J0rdz

Recommended Posts

Im currently designing a website using iframes (at a client's request ofcourse!). Im trying to set the site up so that it is as search engine friendly as possible.The ultimate goal is to try and make it so that all static pages can be linked outside of the frameset, and then be automatically redirected back to the frameset without the frameset pointing back to its original source file.So what im hoping to find is some javascript that i can include in all of the pages that will re-direct back into the frameset. Iv managed to track down a script that allows me to do this, but after it re-directs to the frameset page it inherits the frameset's original source file.This is the code im using at the moment:

<script>if (parent.location.href == self.location.href){	window.location.href = 'index.html'}</script>

with index.html being my frameset.the problem here is that the frameset points to home.html as it's source file, so when i put the script on another page it re-directs back to the frameset, which inturn directs back to home.htmlWhat im hoping for is some kind of script that will tell the frameset to point to the page that was originally opened, not just redirect to the frameset and inherit its source file.Hope this all makes sense.Any help will be much appreciated!!

Link to comment
Share on other sites

Sorry mate, i dont completely follow you here. Im totally in the dark when it comes to Javascript as i've had no training on it at all. So any further information would be greatly appreciated!Alternatively, are there any resources you could point me towards that would delve deeper into what your suggesting?

Link to comment
Share on other sites

Here's an example about reading the querystring:http://ilovethecode.com/Javascript/Javascr...avascript.shtmlThe querystring is everything after the question mark in a URL. You can put the page you want to load in the frame in the querystring, and then on the frameset check if there is a querystring variable with a page name, and if there is then update the source of the frame with the new page.You can't link to a frameset and have it load a specific frame, when you link to a frameset it's just going to open the frameset, which is going to open whatever pages it's telling it to load in the different frames. If you want to open a specific page in the frame, you need to pass that information in something like the querystring and then manually check for that on the frameset page, and update the frame source if necessary. There's just not an automatic way to link to both a frameset and a certain page in a certain frame, you can only link to the frameset.

Link to comment
Share on other sites

Thanks for the further information. Makes it a little bit clearer.That said, its looking like something i wont be able to accomplish with my nonexistent java skills.Let me know if you know of any tutorials, or further information, that specifically tackles the type of thing ill need to be doing.Thanks again for the help!

Link to comment
Share on other sites

You can probably use something like this on your frameset. Make sure to give the frame you want to load content into an ID, and use the ID in the Javascript where it accesses the frame.

<script type="text/javascript">function querySt(k) {  qs = window.location.search.substring(1);  pairs = qs.split("&");  for (i=0;i<pairs.length;i++) {	kv = pairs[i].split("=");	if (kv[0] == k) {	  return kv[1];	}  }  return '';}var page = querySt('page');if (page != ''){  document.getElementById('frame_id').src = page;}</script>

That way you can redirect like I showed, and as long as you have the right filename to load it will put that in the frame. e.g.:index.html?page=products.html

Link to comment
Share on other sites

Thanks again for the help mate, but unfortunately my lack of Java knowledge is working against me here! :)I found this site: http://scriptasylum.com/tutorials/framered...meredirect.htmlAnd tried to implement the code they outline there - but couldnt get it to work. I think it may be because im using an iframe frameset, rather then a normal frameset.I tried to combine the content page code they used along with the code you have outlined, but again, no luck.This is what im using at the moment:In the head of the index.html frameset page im using your code:

<script type="text/javascript">function querySt(k) {  qs = window.location.search.substring(1);  pairs = qs.split("&");  for (i=0;i<pairs.length;i++) {	kv = pairs[i].split("=");	if (kv[0] == k) {	  return kv[1];	}  }  return '';}var page = querySt('page');if (page != ''){  document.getElementById('iframe').src = page;}</script>

'iframe' being my frame IDAnd this is the code im using on my contents page - included in the head:

<script language="javascript">if(self.location==top.location)self.location="index.html?TEST.html";</script>

It re-loads the page in the iframe, but redirects to the iframe's source file again :)Im sure im doing something blatantly wrong here - but i have no idea when it comes to java.

Link to comment
Share on other sites

First, make sure you add the name to the URL also. The name is "page":if(self.location==top.location)self.location="index.html?page=TEST.html";Second, I should have put that code in an event to run after the page is loaded. If you just stick it in the head it will run before the iframe even gets created.

<script type="text/javascript">function querySt(k) {  qs = window.location.search.substring(1);  pairs = qs.split("&");  for (i=0;i<pairs.length;i++) {	kv = pairs[i].split("=");	if (kv[0] == k) {	  return kv[1];	}  }  return '';}window.onload = function(){  var page = querySt('page');  if (page != '')  {	document.getElementById('iframe').src = page;  }}</script>

Wrapping that code in the onload handler will have the code run after the page finishes loading, so the iframe will be created. Just make sure you give it the right ID. That code would look for this:<iframe id="iframe" ...

Link to comment
Share on other sites

GOT IT! Finally! Thanks heaps for the help mate, it's really appreciated!!One last thing.Iv included the code in the frameset at the bottom of the page instead of including it in an onload script. I originally put it in an onload script and called it from my iframe - but when i loaded the page up it directed to the original iframe source first, then re-directed, whereas when i put the code at the bottom of the page it doesn't redirect to the iframe source first. Does that make sense?It still works fine, but are there any downsides to not including the code in an onload script?And now that i have this re-direction script working - will i be penalized or blacklisted at all, when search crawlers are indexing the site?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...