...

View Full Version : adding variable to end of frame url



bunion
07-04-2005, 03:18 PM
Hi, i have this little script which grabs part of the current url and puts it into a javascript variable.


var URL = unescape(window.document.location);

if (URL.indexOf("?") > -1) {
//whether the location contains a "?" or not

var list1 = URL.split("?");
//split at "?";
var list2 = list1[1].split ("=");
//split at "=";
var list2[0] = list2[1];
//assignment
}


So if my user was directed to
www.mywebsite.com/search.html?string=1
the string would become 'list2'.

My search.html page is made up of 2 frames, so my question is how can i pass this variable to the end of one of the urls for one of the frames? So the page will load a different address in one frame depending on the string name that is entered between the ? and the =.

Here is what i have so far:


<head>


<META HTTP-EQUIV="CHARSET" CONTENT="ISO-8859-1">
<META HTTP-EQUIV="CONTENT-LANGUAGE" CONTENT="English">
<META HTTP-EQUIV="VW96.OBJECTTYPE" CONTENT="Document">
<META NAME="RATING" CONTENT="General">
<META NAME="ROBOTS" CONTENT="index,follow">
<META NAME="REVISIT-AFTER" CONTENT="1 Days">
<LINK REL="STYLESHEET" TYPE="TEXT/CSS" HREF="style.css">
</HEAD>

<script language="JavaScript" type="text/JavaScript">

var URL = unescape(window.document.location);

if (URL.indexOf("?") > -1) {
//whether the location contains a "?" or not

var list1 = URL.split("?");
//split at "?";
var list2 = list1[1].split ("=");
//split at "=";
var list2[0] = list2[1];
//assignment
}

</script>

<FRAMESET COLS="22%,78%" BORDER="0" FRAMEBORDER="0" FRAMESPACING="0">
<FRAME NAME="MENU" SRC="http://mysite.com/sidemenu.htm" BORDER="0" FRAMEBORDER="0" FRAMESPACING="0">
<FRAME NAME="MAIN" SRC="http://www.google.com/search?q=" BORDER="0" FRAMEBORDER="0" FRAMESPACING="0">
<FRAMESET ROWS="100%" BORDER="0" FRAMEBORDER="0" FRAMESPACING="0">
</FRAMESET>


Many thanks if you can help in any way.

bunion
07-04-2005, 08:13 PM
bumpage

rlemon
07-05-2005, 12:25 AM
there are quite a few url variable 'grabbers' posted on the forums. then to call it out to a frame you would use document.frames['frame_id'].location = varX; would you not?

bunion
07-05-2005, 07:22 PM
Ok, i tried everything including your suggestion but could not get it working. I have found another small script that will put whatever is after the ? at the end of the address into a variable for me. (ThisAffiliateCode) All i want to do is place this variable at the end of the address for the second frame. I have done loads of searching but nothing seems to work for me. Here is my new code, if anyone could point out what minor adjustment (well i think its minor) is needed it would be really appreciated.


<html>
<head>
<title>Testing</title>
</head>

<script type="text/javascript" language="JavaScript"><!--

function GetAffiliateCode() {
var DefaultAffiliateCode = 'Enter_a_code';
var thisurl = location.href;
var ql = thisurl.indexOf('?
if(ql < 0) { ql = thisurl.indexOf('# }
if(ql >= 0) { return thisurl.substr(ql + 1); }
return DefaultAffiliateCode;
ThisAffiliateCode = GetAffiliateCode();
parent.content.location='http://www.google.com/search?q='+ThisAffiliateCode+';
}
//-->

</script>

<FRAMESET COLS="22%,78%" BORDER="0" FRAMEBORDER="0" FRAMESPACING="0">
<frame src="http://mysite.com/sidemenu.htm" name="nav">
<frame src="http://www.google.com/search?q=" name="content">
</frameset>

</html>

bunion
07-06-2005, 01:25 AM
Is it because the function is not running on page load? Or is it running?! help! noob!

rlemon
07-06-2005, 03:32 PM
Ok, maybe it's just me, but i'm not really understanding what you want here.

you want to post a variable from one frame to another?

so like if a use presses a button on Frame1 the variable 'var1' gets sent to Frame2 via the url?

bunion
07-06-2005, 05:02 PM
Ok imagine someone typed in the address bar

www.mysearchsite.com?example

The page that would load would be made from 2 frames. I would somehow like the word example (or whatever is there after the ?) to be added on to the end of the URL for the second frame. I dont want to post a variable from one frame to the other, i want to post a variable from the address in the address bar to the end of the second frames address. So the frameset code would become

<FRAMESET COLS="22%,78%" BORDER="0" FRAMEBORDER="0" FRAMESPACING="0">
<frame src="http://mysearchsite.com/sidemenu.htm" name="nav">
<frame src="http://www.google.com/search?q=example" name="content">
</frameset>

Thanks for the help so far though.

rlemon
07-06-2005, 08:57 PM
ok, i'l look into this when i get home from work. it can be done.


now will you know what the variable will be (the text after the question mark)?

bunion
07-06-2005, 09:36 PM
All i know is that what is after the question mark could be just letters or numbers or a mixture of both.

sage45
07-06-2005, 10:19 PM
See if this doesn't help you... The purpose and method are a little different but the end result is the same...

http://www.codingforums.com/showpost.php?p=259137&postcount=2

HTH,

-sage-

bunion
07-07-2005, 12:15 AM
That did it! Thankyou very much!

bunion
08-01-2005, 04:46 PM
Im trying to do a similar thing but just with a pop up window but it wont work. Can anyone see whats wrong with my code? For example, if the url below was used the idea is that http://www.google.com/search?q=testing would be shown in the popup.

http://mysite.com/popup.html?newLink=testing


popup.html >

<HTML>
<HEAD>

<SCRIPT LANGUAGE="JavaScript">

function getParams() {
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
}
}
return params;
}
params = getParams();

function popUp(URL) {

newLink = unescape(params["newLink"]);
newAnchor = unescape(params["newAnchor"]);

day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + newLink + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=500,left = 470,top = 200');");
}





</SCRIPT>


</HEAD>




<BODY onLoad="javascript:popUp('http://www.google.com/search?q=')">

</BODY>

</HTML>

bunion
08-01-2005, 07:04 PM
Did it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum