Solved

Open link in a div

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Handling case and special names in javascript 3 26
javascript form submition 2 22
Session on Html 8 42
setInterval() calls function twice in one interval 2 36
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

730 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