My thought was that if I have a lot of documents, instead of having them all accessable from a page menu, I could access them as needed from links in other pages as well by using a url something like this:
Code:
http://www.somesite.com/ajaxpage.html?file=nametoload&title=hotcontent
I could even pass the title of the ajaxpage as a second variable, perhaps.
Then I could use a parser to digest the url. Just like you were passing variables from one page to another. I did find some code that does this (untried and not implemented):
Code:
<script>
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++)
{
var pair = vars[i].split("=");
if (pair[0] == variable) {return pair[1];}
}
alert('Query Variable ' + variable + ' not found');
}
</script>
Now make a request to page.html?x=Hello
<script>
alert( getQueryVariable("x") );
</script>
And I also found:
Code:
function parsequery(){
var arg_pairs = new Object();
arg_pairs.names = new Array();
arg_pairs.values = new Array();
var query = location.search.substring(1);
if(query == "") { return null; }
var pairs = query.split("\&");
for(var i = 0; i < pairs.length; i++)
{
var pos = pairs[i].indexOf('=');
if(pos == -1) { continue; }
var arg_name = pairs[i].substring(0,pos);
var arg_value = pairs[i].substring(pos+1);
arg_pairs.names[i] = arg_name;
arg_pairs.values[i] = arg_value;
}
return arg_pairs;
}
Then somehow I could use the returned variable pairs to give the filename to ajax to automatically display the contents (and perhaps the menu would be disabled). If nothing was returned, then the ajax page would be displayed in a sort-of default mode, permitting the use of the built-in menu. I suppose that this needs to be called in the onLoad event.....
Another use would be to 'seed' the ajax page with selected content.
Bookmarks