• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 455
  • Last Modified:

Open link in a div

Hi there wonder if you can help me?

I have the following links as an example

<a href="http://www.google.com">google</a><br/>
<a href="http://www.yahoo.com">yahoo</a><br/>
<a href="http://www.testing123.com">testing123</a>


When someone clicks on it, the content gets displayed within a DIV. So if someone clicked on google, googles content will be opened up in my div called "link"


Hope that makes sense?

Thanks
0
mousemat24
Asked:
mousemat24
1 Solution
 
callrsCommented:
Link in iframe: http://www.sendspace.com/file/dkd69s

Should be possible to do it for a div, but I don't know how yet.
0
 
daohailamCommented:
try this:

<script>
var req = null;

function get_contents(link) {
      req = null;
      if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
      } else if (window.ActiveXObject) {
            req = new ActiveXObject("Microsoft.XMLHTTP");
      }

      if (req != null) {
            req.open('GET', link, false);
            req.onreadystatechange = recv_data;
            req.send("");
      }
}

function recv_data() {
      if (req.readyState == 4) {
            if (req.status == 200) {
                  document.getElementById('link').innerHTML = req.responseText;
            } else {
                  alert('req error:' + req.statusText);
            }
      }
}
</script>

<a href="javascript:get_contents('http://www.google.com.vn/')">google</a><br/>
<a href="javascript:get_contents('http://www.yahoo.com/')">yahoo</a><br/>
<a href="javascript:get_contents('http://www.testing123.com/')">testing123</a><br/><br/>
<div id="link" style="width: 100%; height: 300px; border: 1px solid black; overflow: auto">
</div>


This works well on IE, but may not work on Firefox, because the security issue (something likes XSS)
0
 
mousemat24Author Commented:
Thanks daohailam!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now