Solved

Open link in a div

Posted on 2006-10-24
3
427 Views
Last Modified: 2010-08-05
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
Comment
Question by:mousemat24
3 Comments
 
LVL 30

Expert Comment

by:callrs
ID: 17800680
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
 
LVL 5

Accepted Solution

by:
daohailam earned 500 total points
ID: 17805783
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
 

Author Comment

by:mousemat24
ID: 17807125
Thanks daohailam!!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 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

17 Experts available now in Live!

Get 1:1 Help Now