By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,600 Members | 1,887 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,600 IT Pros & Developers. It's quick & easy.

Pass Query String to Frame src using Javascript

P: 44
I am using frames on a website. The title link on the title page adds a query string. The link goes to a page with two rows the second has two columns. I want the right column to be changed depending on what the query string is. I have the script to parse the query string here:
Expand|Select|Wrap|Line Numbers
  1. function getQueryVariable(variable) {
  2.     var query =;
  3.     var vars = query.split("&");
  4.     for (var i=0;i<vars.length;i++) {
  5.         var pair = vars[i].split("=");
  6.         if (pair[0] == variable) {
  7.             return pair[1];
  8.         }
  9.     } 
  10.     alert('Query Variable ' + variable + ' not found');
  11. }
  12. var PageLocation = "school/"+getQueryVariable("page")+".html"
The frame is named school and uses this html code:
Expand|Select|Wrap|Line Numbers
  1. <frame noresize frameborder=0 name="school" src="">
I want the frame src to be the “PageLocation” variable. How do I do this in Javascript?

The other way is to have the Javascript direct the frame to the correct page but I don’t know how to do this.

Jul 11 '08 #1
Share this Question
Share on Google+
2 Replies

P: 44
Sorry I forgot to say that the first code in Javascript the other code is HTML.
Jul 12 '08 #2

Expert Mod 15k+
P: 16,027
First you need to access the frame. This depends where the JavaScript code is. Yo can use top to get to the top window. Then use location.href to change the page:
Expand|Select|Wrap|Line Numbers
  1. = PageLocation;
Sorry I forgot to say that the first code in Javascript the other code is HTML.
If you felt you needed to point that out, you can't have much confidence in the person answering your question ;)
Jul 12 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.