Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have a requirement in my project to display one of the table from two. This should happen at the page load. And the condition is based on geographical location.I am able to fetch value according to geographical location(i.e IP) but I am not able to pass that value to page onload event.
Code for it is:
<body önload="setTable('');return false">

Please help me out if my syntax incorrect.

Thanks in advance.
Posted
Comments
enhzflep 29-Aug-13 12:11pm    
Where are you determining location? On the server or the client?
saeel chary 29-Aug-13 12:18pm    
on server. That is not the issue. Only that value I am not able to pass to onload event.It is giving me correct value.
<body önload="setTable('');return false">
enhzflep 29-Aug-13 12:33pm    
Yes, I know that's not the issue. It does however influence how I answer the question...

So, if you're getting the info on the server, why not simply add that info to the page when its being served?

It could be as simple as the following: (assuming php)


$userLocation = doSomeTransformationOnTheClientIPAddress();

printf("<script>\n");
printf("var userLocation = '%s'\n", $userLoation);
printf("</script>\n");


Now, when the page gets to the client, you've got a variable that will hold the information you need to use in order to decide which table to display. Of course, you could just generate the table on the server, doing away with the need to (a) give them access to both tables anyway (b) pass the calculated location to the page in the above manner.

Naturally, server load would be increased.

Personally, I'd be inclined to use the location as determined on the server to control which javascript function I served up. That way, each user would only get javascript capable of generating the table that's relevant to them. Think along the lines of the 'script' I created above.

That way, the client still does the DOM manipulation to create the table and you don't give them a clue about the other information they're being geo-blocked from. Your server has an easy time, your viewer's experience is able to be controlled by you without the easy risk of subversion. :shrug:
ZurdoDev 29-Aug-13 13:02pm    
What's the problem?

1 solution

Instead of calling raw javascript function on body load,use JQuery javascript library to achieve this.Include JQuery library from www.jquery.com.Now perform your stuffs inside load function as below.

JavaScript
var location=Your_fetched_location;
$(window).load(function(){
  if(location== "A")
  {
     $("id_for_table_1").show();
  }
  else
  {
    $("id_for_table_2").show();
  }
});


Hope this will resolve your problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900