Need some javascript help

Status
Not open for further replies.

Christopher

Retired
Messages
14,659
Reaction score
8
Points
0
So I'm trying to make it that when reload=1 is added to the URL, the page refreshes upon doing this one action. I know it works if I don't check if reload=1. But I can't figure out how to check.
BTW, I don't know a thing about javascript. I did this by copying some code :)

Here is what I have. But it doesn't work.
Code:
var queryString = url.replace(/^[^\?]+\??/,'');
var params = tb_parseQuery( queryString );
Code:
if(params['reload'] == 1){
	location.reload(true);
}

Thanks for any help! There might be a credits reward ;)
 
Last edited:

woiwky

New Member
Messages
390
Reaction score
0
Points
0
Try using this instead:

Code:
if (location.search.match('reload=1')) {
    location.search = location.search.replace(/&?reload=1/, '');
}
 

Christopher

Retired
Messages
14,659
Reaction score
8
Points
0
Nope.
I am able to get parameters from the URL.

Code:
TB_WIDTH = (params['width']*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
TB_HEIGHT = (params['height']*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL
That works.
 
Last edited:

woiwky

New Member
Messages
390
Reaction score
0
Points
0
Oh so you *want* to use the params variable? Well in that case I need to see the definiton for the url variable.
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
Alright, so you're placing that code inside of the tb_show() function? At which part exactly? Right after this code?

Code:
var queryString = url.replace(/^[^\?]+\??/,'');
var params = tb_parseQuery( queryString );
 

Christopher

Retired
Messages
14,659
Reaction score
8
Points
0
I put it in tb_remove()

Code:
function tb_remove() {
 	$("#TB_imageOff").unbind("click");
	$("#TB_closeWindowButton").unbind("click");
	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	$("#TB_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	if(params['reload'] == 1){
		location.reload(true);
	}
	return false;
}
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
Ah, that's most likely your problem then since params isn't defined there.

Try changing it to this:

Code:
function tb_remove() {
     $("#TB_imageOff").unbind("click");
    $("#TB_closeWindowButton").unbind("click");
    $("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
    $("#TB_load").remove();
    if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
        $("body","html").css({height: "auto", width: "auto"});
        $("html").css("overflow","");
    }
    document.onkeydown = "";
    document.onkeyup = "";
    var queryString = location.href.replace(/^[^\?]+\??/,'');
    var params = tb_parseQuery( queryString );
    if(params['reload'] == 1){
        location.reload(true);
    }
    return false;
}
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
Try adding 'alert(location.search);' right before 'var queryString...'. If you get no alert box or if you don't see reload=1 in the message, then the code isn't the problem. I just wanna narrow down exactly what the problem is.
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
Well that means that for some reason the current URL has no query. Does the alert box show on page load or when you click a link? How exactly are you adding reload=1 to the query of the URL?
 

Christopher

Retired
Messages
14,659
Reaction score
8
Points
0
Odd.
What I was trying to do is set the reload setting in the URL that the Chat link points to. Like how the height and width ones work.
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
Ah, I see. I think the best way to do that would be by doing this in the tb_show() function:

Code:
var queryString = url.replace(/^[^\?]+\??/,'');
var params = tb_parseQuery( queryString );
window['queryParams'] = params;

So that it creates a global variable named queryParams. And then change the tb_remove() function to:

Code:
function tb_remove() {
     $("#TB_imageOff").unbind("click");
    $("#TB_closeWindowButton").unbind("click");
    $("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
    $("#TB_load").remove();
    if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
        $("body","html").css({height: "auto", width: "auto"});
        $("html").css("overflow","");
    }
    document.onkeydown = "";
    document.onkeyup = "";
    if (queryParams['reload'] == 1){
        location.reload(true);
    }
    return false;
}

I believe that should work fine.
 
T

themasterrocker

Guest
I don't really understand what you're trying to do but i can attempt to help.
To what i can see woiwky is leading you the right way. Is the refresh=1 nesarcary if not why have it there why not have it without because then it refreshes?
 
Status
Not open for further replies.
Top