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

passing url var from a frameset using document.write

P: n/a
I need help to modify the code below to pass url variables from a
framset. The click to run this will be in the mainFrame.

This script works well in a non-frame page. Grabs the current url
variables and adds them to my url.

<script type="text/javascript">
//<![CDATA[
document.write('<a href="my_url.cfm?actionID=close&' +
location.search.substring(1) + '"><img src="launch.jpg" width="75"
height="30" border="0"></a>');
//]]>
</script>
Thanks in advance.
Jul 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Scott wrote:
I need help to modify the code below to pass url variables from a
framset. The click to run this will be in the mainFrame.

This script works well in a non-frame page. Grabs the current url
variables and adds them to my url.

<script type="text/javascript">
document.write('<a href="my_url.cfm?actionID=close&' +
location.search.substring(1) + '"><img src="launch.jpg" width="75"
height="30" border="0"></a>');
</script>


Can you take care of it using one of these approaches:

http://www.mcfedries.com/JavaScript/reframer.asp

if (location.search)
frameSRC = location.search.substring(1);
else
frameSRC = "Put the name of the default frame page here";

http://p2p.wrox.com/archive/beginnin.../2002-03/0.asp

(location.search ? location.search.substring(1):'default.htm') + '">');
similar:
http://www.cybercoded.com/articles/a013_1.asp
http://tech.irt.org/articles/js013/

Mike

Jul 23 '05 #2

P: n/a

Thanks for the reply. Unforutnately I can only use javascript to obtain
the url var from the frameset and pass it along to a coldfusion page. I
am working on a server with alot of restrictions, so it is javascript or
bust.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3

P: n/a

Just realized that I spoke too soon. (sorry late night), the links you
sent were to js not asp. please accept my apology. I will check those
out now and report back.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #4

P: n/a
scott wrote:
Just realized that I spoke too soon. (sorry late night), the links you
sent were to js not asp.


Maybe see if you can work with one of these if those don't work out for you:

top.location.href
window.location.href

alert('top.location.href\n'+top.location.href+'\nw indow.location.href\n'+window.location.href);

Good Luck,
Mike

Jul 23 '05 #5

P: n/a
Mike, thanks again for the help. I am very shaky with js.

I reviewed those links, and I think I should clarify my problem a bit
more. It appears those links explain how to work with js to either
pass or pull data so that js can render the framesets for you.
I need to use js to read the url variables from a frameset page. I am
very average with js, but I think my solution would be something like
adding to the script to let it know I was working in a frameset.
How would I grab everything after the questionmark in the following
url from a frameset and append it to a link.

So that this
foo.com?var1=1234&var2=5678

Gets me this
myUrl.com?var1=1234&var2=5678

Thanks again!!
Jul 23 '05 #6

P: n/a
Scott wrote:
<snip>
I need to use js to read the url variables from a frameset page. >
How would I grab everything after the questionmark in the following
url from a frameset and append it to a link.

So that this
foo.com?var1=1234&var2=5678

Gets me this
myUrl.com?var1=1234&var2=5678


Sorry I wasn't clearer in my last message, see if this will work for
you. It takes advantage of "top" which will jump you directly to the top
of the frame tree, so you can do a location.search on the top window
from any frame, this worked in my IE6, Netscape7, Firefox 0.8.

function show() {
alert('top.location.search ' + top.location.search);
alert('top.window.location.search '+top.window.location.search);
alert('top.window.location.search.substring(1)
'+top.window.location.search.substring(1));
}

To read about using "top":

http://www.quirksmode.org/js/frameintro.html
http://www.yourhtmlsource.com/javasc...ingframes.html

Good Luck,
Mike

Jul 23 '05 #7

P: n/a
Scott wrote:
I need help to modify the code below to pass url variables from a
framset. The click to run this will be in the mainFrame.

This script works well in a non-frame page. Grabs the current url
variables and adds them to my url.

<script type="text/javascript">
//<![CDATA[
document.write('<a href="my_url.cfm?actionID=close&' +
location.search.substring(1) + '"><img src="launch.jpg" width="75"
height="30" border="0"></a>');
//]]>
</script>

Thanks in advance.


The frames in a frameset have no access to any information passed on
the URI, because they are defined as:

<frame src="somepage.html" ... />

Even if the frameset file containing the above HTML was passed items
on the URI, somepage.html will have no access to that information
because it is being requested without them. If you what you want is
somepage.html to have access to information passed to the frameset
containing it, then use:

frameset.html ---

html>
<head>
</head>
<script type="text/javascript">
var query = window.location.search.substring(1);
if (query != '') {
query = '&' + query;
}
document.write(
'<frameset rows="86,*" border="0">' +
'<frame name="top_frame" src="top.html?page=top' +
query +
'" noresize="noresize" scrolling="no" marginheight="0"
marginwidth="0" />\r\n' +
'<frame name="body_frame" src="body.html?page=body' +
query +
'" noresize="noresize" marginheight="0" marginwidth="0" />' +
'</frameset>'
);
</script>
</html>

top.html and body.html ---

<html>
<head>
</head>
<body onload="alert(window.location.search);">
</body>
</html>
Load frameset.html?x=y and you should see that passed to both top.html
and body.html.

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.