?
Solved

Open link in a div

Posted on 2006-10-24
3
Medium Priority
?
450 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

649 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