Solved

Open link in a div

Posted on 2006-10-24
3
431 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Capture logon name 13 73
how can i extend ? 2 44
how can i get 4 nd 5 ? 3 13
Html CheckBox obtain Its Value 5 15
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

803 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