dqyuipw44576
2016-08-22 10:25
浏览 46

如何在警报脚本中插入GEOIP标注?

I'm looking for a way to call out the user's city within the alert script, I have tried document.write but I'm no coder and spent several hours to no avail. I can use

<span id="city">{cityname}</span> 

on the page itself, but cannot get it to work in the alert script.

<head>
<script type="text/javascript" src="http://www.jsgeoip.com/geoip.js">   </script>
</head>
<body>
<script> 
$(document).ready(function() {
$('#city').html(geoip_city());
}); 
</script>
<script>alert('Welcome CITY HERE User');</script>
</body>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doujia1679 2016-08-22 10:30
    已采纳

    Just move the alert call to after you get the geoip. No use having that second script block, do it all in the one ready function:

    $(document).ready(function() {
        var geoip = geoip_city();
        $('#city').html(geoip);
        alert('Welcome ' + geoip + ' User');
    });
    
    点赞 评论

相关推荐 更多相似问题