Scottie wrote:
[color=blue]
> In JavaScript, how do you pass a var from one HTML file to another
> one? I "own" both of these HTML files.[/color]
Cookies, parsing the query string, frames, some server side language reading
POST, GET or the cookies and writing a <script> element dynamically. There
are several options.
--
David Dorward <http://blog.dorward.me .uk/> <http://dorward.me.uk/>
What I did was:
var str = window.location .search;
if (str != "") {
var temp = str.split('=');
alert(temp[1]);
}
else {
alert("This is NULL");
}
and it works. Thanks.
Scott
David Dorward <dorward@yahoo. com> wrote in message news:<c8muck$n4 a$1$8302bc10@ne ws.demon.co.uk> ...[color=blue]
> Scottie wrote:
>[color=green]
> > In JavaScript, how do you pass a var from one HTML file to another
> > one? I "own" both of these HTML files.[/color]
>
> Cookies, parsing the query string, frames, some server side language reading
> POST, GET or the cookies and writing a <script> element dynamically. There
> are several options.[/color]
Scottie wrote:
[color=blue]
> David,
>
> What I did was:
> var str = window.location .search;
> if (str != "") {
> var temp = str.split('=');
> alert(temp[1]);[/color]
What if str.split('=') doesn't create an array, or doesn't create more then one element in the array?
What if there are multiple items being passed on the URL? You'll get both the first value and all the
remaining text from window.location .search.
[color=blue]
> }
> else {
> alert("This is NULL");[/color]
No, it's not null, because that's not what you're testing str against. Your condition says [if (str !=
"") {], so the else branch of that condition is that (str == ""). In fact, if str is null, it will take
the positive branch (because (null != ""), which will result in an error when you attempt to do
str.split().
[color=blue]
> }
>
> and it works. Thanks.
>
> Scott[/color]
Here is a much better solution:
var s = window.location .search;
// set s for testing
s = 'a=b&c=d&YourAt tribute=MyValue &e=f&g=h';
// find the exact value associated with your attribute
(new RegExp('YourAtt ribute=([^&]+)')).test(s);
if (RegExp.$1) {
alert(RegExp.$1 );
} else {
alert('There is no value for "YourAttribute" ');
}
Comment