Click to See Complete Forum and Search --> : call function on another page from URL
favaboy
06-17-2004, 03:18 AM
Hi to all,
I've a problem that gives me the creeps.. uhm that's it:
In a page, let's say page1.aspx I've a normal link that points to another page.
When i click it, i must go to page2.aspx and execute a function written in that page2 passing a parameter to it.
I've found infos for managing external calls just for frames, but what if I must do it in another page from a url?
Tnx very much for any help!!
Cya soon
Pittimann
06-17-2004, 04:28 AM
Hi!
Let's say, the parameter should be 'kkk' and you have a link to open the second page like:
<a href="page1.aspx?xx=kkk" target="_blank">click</a>
If you only need one parameter to be passed, this will do the job in page2.aspx:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
var param=location.search.split('=')[1];
function thisCameIn(val){
alert(val);
}
//-->
</script>
</head>
<body onload="thisCameIn(param)">
</body>
</html>location.search gives you everything in the url starting with the "?". So you just have to split that string at the "=". Then you will have an array containing 'kkk' as the second element which you can reference with "location.search.split('=')[1]" ([1] standing for the second element, because array indexes start with zero).
If you have more stuff in the url, you will need to split the search string into sub arrays (at the "&"s) and these have to be splitted again at the "=", but I guess, you don't need that for your purpose.
Cheers - Pit
favaboy
06-17-2004, 05:39 AM
Now that's A-M-A-Z-I-N-G !!
Tnx a lot Pittimann, that works great for my purpose ;)
Bye!!!
:D
Pittimann
06-17-2004, 07:19 AM
Hi!
You're welcome!
Cheers & good luck - Pit
favaboy
06-17-2004, 09:28 AM
Hi! I'm here again for one last trick:
The first time page loads, since param is nothing, IE catch it into the taskbar. I've made an "if" statement like this
if (param != null)
{
function thisCameIn(val){
menMsgFn(val);
lightup("pic" + val)
}
}
else
{
function thisCameIn('1'){
menMsgFn('1');
lightup('pic1')
}
}
Still hangs, with "Param is undefined" and "Expected identifier" .. gosh.. what is wrong?
Tnx
Hello, favaboy. Please try the following.
<script type="text/javascript">
var param=location.search.split('=')[1];
function thisCameIn(val){
if (val != null)
{
menMsgFn(val);
lightup("pic" + val)
} else {
menMsgFn('1');
lightup('pic1')
}
}
</script>
favaboy
06-17-2004, 09:44 AM
Tnx Jona, maybe today it's so hot I should wash my face with fresh water, for I haven't noticed what's wrong previously... :P
Bye
Originally posted by favaboy
Tnx Jona, maybe today it's so hot I should wash my face with fresh water, for I haven't noticed what's wrong previously... :P
Does this mean your most recent problem has been solved?
favaboy
06-17-2004, 09:54 AM
Yes of course, thank you very much ;)