Pass Query String to Frame src using Javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • I Hate My Computer
    New Member
    • Mar 2007
    • 44

    Pass Query String to Frame src using Javascript

    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:
    Code:
    function getQueryVariable(variable) {
    	var query = window.location.search.substring(1);
    	var vars = query.split("&");
    	for (var i=0;i<vars.length;i++) {
    		var pair = vars[i].split("=");
    		if (pair[0] == variable) {
    			return pair[1];
    		}
    	} 
    	alert('Query Variable ' + variable + ' not found');
    }
    var PageLocation = "school/"+getQueryVariable("page")+".html"
    The frame is named school and uses this html code:
    Code:
    <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.

    Thanks,
    Josh
  • I Hate My Computer
    New Member
    • Mar 2007
    • 44

    #2
    Sorry I forgot to say that the first code in Javascript the other code is HTML.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      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:[code=javascript]top.school.loca tion.href = PageLocation;[/code]
      Originally posted by I Hate My Computer
      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 ;)

      Comment

      Working...