Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing parameters through hyperlink to use in another hyperlink 1

Status
Not open for further replies.

TrentGreenawalt

Technical User
Jan 18, 2002
159
US
I have a specific request that I have been trying to figure out all day and I hoping that one of you can help me.

Here is what I am trying to accomplish:

Currently, I have a main page on our site with a direct link to another site. What I am trying to do is create a framed page with our logo in the top page, and display the other page in the lower window.

Now I have figured out how to do this by creating a page for each additional webpage I want to display, but I would like to create one "framed page" that will be able to display any link I send to it with the same frame at the top.

Here is what I have so far: (This is an example, but the site I am actually linking to)

The main page opens the new window with this line:
<head>
</head>
<Body>
Please visit cnn.com for all your news needs:
<a href="Frametest.html?weblink=http://www.cnn.com">CNN</a>
</Body>

Then the frametest.html file contains this code:
<HEAD>
<TITLE>ABC Company</TITLE>
</HEAD>
<FRAMESET rows= 57,* frameBorder=1>
<FRAME src="header_files/header.htm" NORESIZE scrolling="no">
<FRAME src="</FRAMESET>


So as you can see the <Frame src=" needs to be replaced with the value that I passed in the original hyperlink.

I have played around with some javascript, but I don't know it that well and really don't know what I am doing. Here is what I attempted, but it never worked.

<HEAD>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<script language="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! -->

<!-- Begin
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.split('=');
params[nameVal[0]] = nameVal[1];
}
}
return params;
}

params = getParams();

// End -->
</script>

<TITLE>ABC Company</TITLE>
<script language="JavaScript">
<!-- Begin
wlink = unescape params "Weblink"]);
// End -->
</script>

<FRAMESET rows= 57,* frameBorder=1>
<FRAME src="header_files/header.htm" NORESIZE scrolling="no">
<FRAME src=wlink>
</FRAMESET>
</HEAD>

So there is where I am at. I really hope that you can help me with this. I really appreciate your help in this matter.

Thanks,
Trent
 
I took just a quick look at your code and I saw this line has errors:
Code:
 wlink = unescape params "Weblink"]);

Lee
 
Hi Lee,

Yes I am aware of that, and that is why I am posting this message. I appreciate you looking over the code. I have actually switched the receiving page up a bit and have brought the variable over and assigned it to a new variable. Now I need to figure out how to use it in a hyperlink string as a variable:

Here is the new code for the second page: frametest.html:
html>
<head>
<!-- head stuff -->
<script type="text/javascript">
<!-- hide from old browsers

function getValue(varname)
{
// First, we load the URL into a variable
var url = window.location.href;

// Next, split the url by the ?
var qparts = url.split("?");

// Check that there is a querystring, return "" if not
if (qparts.length == 0)
{
return "";
}

// Then find the querystring, everything after the ?
var query = qparts[1];

// Split the query string into variables (separates by &s)
var vars = query.split("&");

// Initialize the value with "" as default
var value = "";

// Iterate through vars, checking each one for varname
for (i=0;i<vars.length;i++)
{
// Split the variable by =, which splits name and value
var parts = vars.split("=");

// Check if the correct variable
if (parts[0] == varname)
{
// Load value into variable
value = parts[1];

// End the loop
break;
}
}

// Convert escape code
value = unescape(value);

// Convert "+"s to " "s
value.replace(/\+/g," ");

// Return the value
return value;
}

// end hide -->
<script type="text/javascript">
<!-- hide
var weblink = getValue("weblink");
// end hide -->
</script>

<FRAMESET rows= 57,* frameBorder=1>
<FRAME src="header_files/header.htm" NORESIZE scrolling="no">
<FRAME src="weblink">
</FRAMESET>

</head>
<body>
<h1>Hello, It works
<script type="text/javascript">
<!-- hide
var weblink = getValue("weblink");
document.write(weblink);
// end hide -->
</script>
</h1>
</body>
</html>
</HEAD>

Now this works to display the variable, so it is stored, but I can't get it to show the hyperlink in the framed page. Any help is appreciated.

The problem lies in the line above:
<FRAME src="weblink">

Thanks,
Trent
 
1) You have your frameset and frames inside the head
2) You have a frame src that isn't a URL
3) and you document.write() something in the middle of the page without giving us a hint what the value actually is that was passed in the URL.

That's 3 strikes on one page.

Lee
 
Code:
<FRAME src="weblink">
Is where you're going wrong. You can't mix and match HTML with Javascript variables.

Use an [tt]onload[/tt] handler in your frameset to call a function which sets the [tt]src[/tt] to the required url.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Webflo
 
HI lee and Dwarf,

Thanks for your comments guys/gals, but I am aware this isn't correct and I am not that knowledgable of javascript.

Lee - if you look at the first post I am passing the hyperlink of into that variable.

Also - the (document.write() something in the middle of the page without giving us a hint what the value actually is that was passed in the URL.) was put in there to make sure the variable was getting defined and it was. I could display it on the page. I just never removed the code for that. I don't need to display it. I need the lower part of the frame to be in this case. I hope this helps.


Dwarf - I am aware that I can't have html with java. I don't know the java code to place that variable into the frame src = field. Can you please provide an example of this "onload" handle for me such as:

<FRAMESET rows= 57,* frameBorder=1>
<FRAME src="header_files/header.htm" NORESIZE scrolling="no">
<FRAME src = ***Java variable/code goes here***>
</FRAMESET>

I just don't know what to put in the above spot. The variable is getting defined like I said above, but I can't get it to run in the above code. Is there a way in jave or another language to get this to work?

Your help is greatly appreciated. I have about 200 links on our website that need this feature build into it, so it is either create 200 individual frame websites or figure this out:)

Thanks again,
Trent
 
zilla said:
Dwarf - I am aware that I can't have html with java.
Javascript. Not Java.

zilla said:
I don't know the java code to place that variable into the frame src = field.
Like I said, you can't mix and match HTML code with Javascript variables. Javascript code can only be interpreted when it's bound up inside a [tt]script[/tt] tag or as an event handler... like the frameset's [tt]onload[/tt] event handler. You can put any Javascript (or Java for that matter) code in your HTML like you suggest, it will all get you the same result, ie, it won't work.

zilla said:
Can you please provide an example of this "onload" handle for me such as:
While any example I might provide that conforms to your dictated specification would not be very effective for the aforementioned reasons, I'm happy to provide an example that works:
Code:
<html>
<head>
<script type="text/javascript">
function setBottomFrame(){
	var url="[URL unfurl="true"]http://www.google.com";[/URL]
	window.frames['targetFrame'].location = url;
}
</script>

<FRAMESET rows="57,*" frameBorder="1" onload="setBottomFrame();">
<FRAME src="header_files/header.htm" NORESIZE scrolling="no">
<FRAME src="#" name="targetFrame">
</FRAMESET>
</head>
</html>





Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Webflo
 
Example of using frames from w3.org.


Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
   "[URL unfurl="true"]http://www.w3.org/TR/html4/frameset.dtd">[/URL]
<HTML>
<HEAD>
<TITLE>A simple frameset document</TITLE>
</HEAD>
<FRAMESET cols="20%, 80%">
  <FRAMESET rows="100, 200">
      <FRAME src="contents_of_frame1.html">
      <FRAME src="contents_of_frame2.gif">
  </FRAMESET>
  <FRAME src="contents_of_frame3.html">
  <NOFRAMES>
      <P>This frameset document contains:
      <UL>
         <LI><A href="contents_of_frame1.html">Some neat contents</A>
         <LI><IMG src="contents_of_frame2.gif" alt="A neat image">
         <LI><A href="contents_of_frame3.html">Some other neat contents</A>
      </UL>
  </NOFRAMES>
</FRAMESET>
</HTML>

All W3.org examples I've found show the frameset outside the <head>...</head> tags. I've only used frames a couple times, so don't have a lot of experience with them. Nowadays there is almost always a better way to design pages than using frames.

Lee
 
Good morning guys,

Well I worked on this a bit after I posted and actually went out to another site as well for help. An expert from actually provided me with an example that I could work with. Dwarf your example is very similar to theirs and I am sure it would work to, so i gave you a star for the post and a big thanks to both you and Lee for helping me with this.

Here is a copy of what I used to accomplish my specific task:

Posted from: Well Vidi is sure are a life saver. I just wanted to post my solution to the exact task I was trying to accomplish for the world to see and use. Your code helped me to figure out what was going on and I was able to take it a step further to get the desired result.

Here is what I did: (below are examples for testing purposes)

First page named firstpage.html:
<html>
<Title>Company Title</Title>
<body>
<li><a href= "frameTest.html?link=http://www.cnn.com">CNN</a>
<li><a href= "frameTest.html?link=http://www.yahoo.com">Yahoo</a>
<li><a href= "frameTest.html?link=http://www.google.com">Google</a>
</body>
</html>

Second page named frametest.html:
<html>
<Title>Company Title</Title>
<frame>
<frameset rows= "57,*" frameBorder=1>
<frame src="topPage.html" name="topPage" NORESIZE scrolling="no">
<frame src="" name="bottomPage">
</frame>
</html>

Third and most grateful page named topPage.html:
<html>
<Head>
<TITLE>Company Title</TITLE>
<STYLE>* {
PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 2px
}
BODY {
BACKGROUND: url() repeat-x
}
#header {
BACKGROUND: url(header_files/companylogo.jpg) no-repeat; WIDTH: 800px; HEIGHT: 100px
}
#header IMG {
BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: none
}
</STYLE>
</HEAD>
<body>
<DIV id=header><A href=" target=_blank>
<IMG height=60 src="header_files/transparent.gif" width=1280></A>
</DIV>
</BODY>
</HTML>

<script>
function getParams()
{
var myUrl=parent.location.href;
var beginIndex = myUrl.indexOf('?');
var bottomUrl = "";

if (beginIndex != -1)
{
var link = myUrl.substring(beginIndex+1, myUrl.length).split('=');
bottomUrl = link[1];
}
return bottomUrl;
}
parent.bottomPage.location.href = getParams();
</script>


Thank you so much everyone!

Sincerely,
Trent G - Milwaukee, WI

Follow Up Question:
The only problem I am dealing with now is the active x and javascript blocking the pages as they pop up. This doesn't cause me a problem (I allowed it), but it is sure too in real time with others on the site. Is there anyway to avoid this, so we avoid the blocks?
 
Have you considered using server-side scripting (ASP or PHP) to create the frametest.html link on the server? That would avoid Javascript blocking. If you use ASP, you can do it like this:
Code:
<frame src="<%=Request.QueryString("link")%>" name="bottomPage">

Lee
 
HI Trollacious,

I am interested to know more from you about this, because as you said the java is getting blocked. I don't know any ASP, so your help is much appreciated. What else would I need to add into my code to get this to work in addition to what you have above.

It can't be as easy as just changing up that line of the code is it?

Thanks,
Trent
 
I am interested to know more from you about this .... I don't know any ASP

It's probably best to continue this discussion here:

forum333

It is starting to get outside the scope of the javascript forum.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top