私は e コマース サイトを持っており、ユーザーがいる国を特定するスクリプトを作成しています。その国が出荷先の 4 か国のうちの 1 つである場合は、その国に出荷することを示すステートメントを返します。IP ロケーション サービス スクリプト (" http://smart-ip.net/geoip-json callback=GetUserInfo") と HTML ドキュメントに結合されたスクリプトでこれを実現できましたが、外部.jsドキュメントをsnするスクリプト スクリプトを取得してIPロケーションサービススクリプトを開始する方法がわかりません。
元の HTML ドキュメント (作業中)
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Get User Country</title>
<script src="http://code.jquery.com/jquery-1.8.2.js" type="text/javascript"></script>
<script type="text/javascript">
var strcountry
function GetUserInfo(data) {
strip = data.host;
strcountry = data.countryName;
}
$(function ()
{
BindUserInfo();
})
function BindUserInfo()
{
document.getElementById('lblCountry').innerHTML = strcountry;
}
</script>
<script type="text/javascript" src="http://smart-ip.net/geoip-json callback=GetUserInfo"></script>
</head>
<body>
<a id="weship"/>
<script type="text/javascript">
if (strcountry == "United States")
{
document.getElementById('weship').innerHTML = 'We ship to The United States';
}
else if (strcountry == "Singapore")
{
document.getElementById('weship').innerHTML = 'We ship to Singapore';
}
else if (strcountry == "Malaysia")
{
document.getElementById('weship').innerHTML = 'We ship to Malaysia';
}
else if (strcountry == "Hong Kong")
{
document.getElementById('weship').innerHTML = 'We ship to Hong Kong';
}
</script>
新しい HTML ファイル呼び出しスクリプト (index.html)
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Get User Ountry </title>
<script src="http://code.jquery.com/jquery-1.8.2.js" type="text/javascript"></script>
<script type="text/javascript" src="http://smart-ip.net/geoip-json?callback=GetUserInfo"></script>
</head>
<body>
<a id="weship"/>
<script type="text/javascript" src="countrylocate.js"></script>
</body>
</html>
私のスクリプト(countrylocate.js)
var strcountry
function GetUserInfo(data) {
strip = data.host;
strcountry = data.countryName;
}
$(function ()
{
BindUserInfo();
})
function BindUserInfo()
{
document.getElementById('lblCountry').innerHTML = strcountry;
}
if (strcountry == "United States")
{
document.getElementById('weship').innerHTML = 'We ship to The United States';
}
else if (strcountry == "Singapore")
{
document.getElementById('weship').innerHTML = 'We ship to Singapore';
}
else if (strcountry == "Malaysia")
{
document.getElementById('weship').innerHTML = 'We ship to Malaysia';
}
else if (strcountry == "Hong Kong")
{
document.getElementById('weship').innerHTML = 'We ship to Hong Kong';
}