This code performs the function 'move_up()' when I add '?biog=2' on the end of the URL:
- Code: Select all
(function () {
var $_GET = (function () {
var a, i, o = (window.location.search.substring(1)).split('&');
for (i in o) {
a = o[i].split('=');
o[a[0]] = a[1];
}
return o;
})();
if($_GET['biog'] == 2) {
move_up();
}
else {
alert('no luck');
}
})();
This code scrolls the div 'scroll_clipper' down by 50px:
- Code: Select all
function move_up() {
scroll_clipper.scrollTop = 50;
}
The problem is, they don't work together. 'move_up()' scrolls the div down perfectly when triggered by a link:
- Code: Select all
<a href='javascript:move_up()'>Move UP</a>
And, to test the first code, I've tried changing 'move_up()' to:
- Code: Select all
function move_up() {
document.write('Hello);
}
Which (with the first code) writes hello when I load the page as http://www.example.com/page.html?biog=2
Full code here (to prove it works):
- Code: Select all
function move_up() {
document.write('Hello');
}
(function () {
var $_GET = (function () {
var a, i, o = (window.location.search.substring(1)).split('&');
for (i in o) {
a = o[i].split('=');
o[a[0]] = a[1];
}
return o;
})();
// Now the GET querystring values are accessible via $_GET['key']
// for example, given querystring ?name=Fotiman&var=1&foo=bar
// if ($_GET['var'] == 1) {
// dosomething
// }
if($_GET['biog'] == 2) {
move_up();
}
else {
alert('no luck');
}
})();
Why do they work in all of those combinations but not the one I need?
I've got the basics of JavaScript but I'm still new to it. Any help is greatly appreciated.


