PDA

View Full Version : Dynamic Ajax Content-Page not Displaying second time clicked



Morisatwork
01-25-2007, 12:36 AM
1) Script Title: Dynamic Ajax Content

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

3) Describe problem: Page not Displaying second time clicked

Hi Guys

I have added the following code to automatically load a page from a menu/link call. The page in question loads ok the first time however if it is called again it is not displayed ie the user will need to manually select the page from the page

the menu call is : customercare.asp?page=privacypolicy.htm
and there are a number of such pages.

My javascript knowledge is in an embryonic stage so I am not sure what to be looking for.

I do not think I have changed the original Dynamic Ajax Content code.

In head



<script language="JavaScript" type="text/JavaScript">
function getQueryValue(name) {
var match = (new RegExp('[?&;]' + name + '=([^&;#]*)')).exec(document.URL);
return match ? unescape(match[1]) : null;
}
function loadstart(){
var page = getQueryValue('page');
if(page != null)
{ajaxpage(page, 'thecontent');}
else
{ajaxpage('privacypolicy.htm', 'thecontent');}
}
</script>


in body



<body onLoad="javascript:window.print();">


<script type="text/javascript">
window.onload = loadstart();
</script>


thanks

Moris

jscheuer1
01-25-2007, 05:32 PM
Try this one instead of your getQueryValue():


function getQueryValue(key_str) {
var query = window.location.search.substr(1);
var pairs = query.split("&");
for(var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split("=");
if(unescape(pair[0]) == key_str)
return unescape(pair[1]);
}
return null;
}

Yours looked a bit shaky to me but, I may just have misunderstood it.

And, I'd get rid of this:



onLoad="javascript:window.print();"

At best, it will be overriden by:



<script type="text/javascript">
window.onload = loadstart();
</script>

at worst, who knows?