Solved

javascript to html map

Posted on 2016-10-20
8
39 Views
Last Modified: 2016-10-20
I have below html codes
inside of map. how can i capture the json.ip into html ip= json.ip?

I am actually able to get the public ip. Just try to put the ip value into html


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <!-- START: Here's the IP stuff -->
  <script type="application/javascript">
      function getIP(json) {
          alert("My public IP address is: " + json.ip);
      }
  </script>
  <script type="application/javascript"
          src="http://api.ipify.org?format=jsonp&callback=getIP">
  </script>
  <!-- END: IP Stuff -->
</head>
<body>
    <form id="form1">
    <div>
    <map name="planetmap">
     <area shape="rect" coords="0,388 185,429" alt="Chino, CA" target="_blank" href="http://www.gdfg.biz/ClickRecoder.aspx?rentalLocation=SMC-Chino&URL=http://www.sharsdfgfd.com?ip=">
   </map>
    </div>
    </form>
</body>
</html>
0
Comment
Question by:ITsolutionWizard
  • 4
  • 3
8 Comments
 
LVL 21

Expert Comment

by:Kim Walker
ID: 41853101
You want the IP address to appear on the page? Try this:
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <!-- START: Here's the IP stuff -->
    <script type="application/javascript">
        function getIP(json) {
            document.write("My public IP address is: " + json.ip);
        }
    </script>
    <!-- END: IP Stuff -->
</head>
<body>
    <form id="form1">
    <div>
        <map name="planetmap">
            <area shape="rect" coords="0,388 185,429" alt="Chino, CA" target="_blank" href="http://www.gdfg.biz/ClickRecoder.aspx?rentalLocation=SMC-Chino&URL=http://www.sharsdfgfd.com?ip=">
        </map>
    </div>
    </form>
    <p>
    <!-- START: More IP stuff -->
    <script type="application/javascript"
        src="http://api.ipify.org?format=jsonp&callback=getIP">
    </script>
    <!-- END: more IP stuff -->
    </p>
</body>
</html>

Open in new window

Always select your code and click the CODE button at the top of the question/comment window to format your code to be styled for easy parsing.
0
 

Author Comment

by:ITsolutionWizard
ID: 41853112
i do not want ip appear on the webpage. I need to go ip="json.ip"
Your solution does not work to me. Thanks
0
 
LVL 9

Expert Comment

by:Karen
ID: 41853149
if you are using jquery in your project, it is easy

function getIP(json) {
    $("area").attr("href","http://www.gdfg.biz/ClickRecoder.aspx?rentalLocation=SMC-Chino&URL=http://www.sharsdfgfd.com?ip=" + json.ip);
}

Open in new window


It can be done in plain javascript but is a bit more complicated, let me know if you need that.
0
 

Author Comment

by:ITsolutionWizard
ID: 41853175
I need plain JavaScript
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 9

Expert Comment

by:Karen
ID: 41853185
function getIP(json) {
    var x = document.getElementsByTagName("area");
    if (x.length) {
        x[0].href = "http://www.gdfg.biz/ClickRecoder.aspx?rentalLocation=SMC-Chino&URL=http://www.sharsdfgfd.com?ip=" + json.ip;
    }
}
0
 

Author Comment

by:ITsolutionWizard
ID: 41853222
But I do have more than 1 area. Both above solutions won't work...

<map name="planetmap">
     <area shape="rect" coords="0,388 185,429" alt="Chino, CA" target="_blank" href="http://www.gdfg.biz/ClickRecoder.aspx?rentalLocation=SMC-Chino&URL=http://www.sharsdfgfd.com?ip=">

     <area shape="rect" coords="0,388 185,4292" alt="Pomona, CA" target="_blank" href="http://www.gdfg.biz/ClickRecoder.aspx?rentalLocation=SMC-Ponoma&URL=http://www.sharsdfgfd.com?ip=">


   </map>
0
 

Author Comment

by:ITsolutionWizard
ID: 41853229
and how to call  getIP(json) ? what I need to put inside of json?
0
 
LVL 9

Accepted Solution

by:
Karen earned 500 total points
ID: 41853240
function getIP(json) {
    var x = document.getElementsByTagName("area");
    if (x.length) {
        for (j=0;j<x.length;j++) {
            x[j].href+= json.ip;
        }
    }
} 

Open in new window


You should not need to call getIP, it looks like it is a callback and so api.ipify.org will call it.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
The viewer will learn how to dynamically set the form action using jQuery.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now