Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Load different JS files for various users
Old 03-06-2011, 11:56 PM Load different JS files for various users
Junior Talker

Posts: 2
Name: Mark Battistella
Trades: 0
Hello!

So I'm quite new to JS and mainly focused on css and html prior to taking on JS coding.

I am designing a webstore that relies on a pre-scripted file called "SimpleCart(js)", and the file is very well in good. However, as the items to be sold will be available overseas, shipping costs will vary according to user distances.

Now currently the user will select their country and it will set a cookie to tell the cart the shipping cost, but I was wondering if it was possible to load a differenct JS file according to the users location (IP address) - using an IP locating script.

So for example:
if the user is from America, load Amercia.js
else
if the user is from Australia, load Australia.js
else
if the user is from... etc.

What varies, is the shipping calculation for each location, while the actual content is the same.

But I would like to know if there is an easy way to load another JS file from within a script?

Thank you,
Mark
batta is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-07-2011, 07:47 AM Re: Load different JS files for various users
Extreme Talker

Posts: 246
Trades: 0
Please check out this site, it has your answer.

http://www.javascriptkit.com/javatut...criptcss.shtml
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
stbuchok is offline
Reply With Quote
View Public Profile
 
Old 03-08-2011, 06:24 AM Re: Load different JS files for various users
phpdasan's Avatar
Experienced Talker

Posts: 37
Name: Karthick B
Trades: 0
May be you shall use this script

HTML Code:
<script type="text/javascript">
  // plain JavaScript example
  function jsonpCallback(data) { 
    alert('Latitude: ' + data.latitude + 
          '\nLongitude: ' + data.longitude + 
          '\nCountry: ' + data.address.country); 
  }
</script>
<script src="http://api.wipmania.com/jsonp?callback=jsonpCallback"
        type="text/javascript"></script>
And based on the country, you load the respective js file.
__________________
There is no secret ingredient.
phpdasan is offline
Reply With Quote
View Public Profile
 
Old 03-24-2011, 04:57 AM Re: Load different JS files for various users
Junior Talker

Posts: 2
Name: Mark Battistella
Trades: 0
Hello!

Thank you for the replies, and apologise for my delayed turn around.

Now, stbuchok your website seems difficult for my level. Sorry.


phpdasan your method seems easy so much so that I don't know how to implement it.

I know it's probably easy work, but JS isn't my strong point. I was wondering if it was possible to set the files in an array? The '[i]' thing, and call them using that? I'm not sure if you can, but I know you can use it for images.

Also is it possible to do this:
var EN=US,AUS,GB
var AS=KOR,JAP,GB

if location is equal to EN run eng.js,
else
if country is equal to AS run asia.js ... etc.

So in that respect, make the countries in the certain category all equal one variable, and then if the script detects it as a variable that has been defined run the script..

I'm just throwing around ideas, but would love if somebody could shed some light :]
batta is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Load different JS files for various users
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.34936 seconds with 12 queries