1

how to load the content of a html url in the same view in javascript.

3
  • 1
    Please be (much) more specific. Commented Jan 21, 2011 at 10:18
  • I am parsing a xml file and the link which i am talking about, is the one the content which i get after the parsing is done. Now i want to get the content of that html link in order to display that content on some view. Commented Jan 21, 2011 at 11:01
  • Where do all the newbies come from recently? Commented Jan 21, 2011 at 12:12

4 Answers 4

1

Another option is to use an IFRAME tag.

Sign up to request clarification or add additional context in comments.

2 Comments

+1 because I had also given same answer and I think this is the right way to do it...
After adding iframe tag in html of dashcode(web application IDE for iphone), i am getting an error which says "For Security reasons framing is not allowed".
0

If you're talking about loading another page's content in Javascript, you need to use AJAX.

<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for older IE
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>

<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>

</body>
</html>

More info and examples at W3Schools. Note that AJAX doesn't work across different domains for security restrictions.

2 Comments

I am working in Dashcode On Mac so getting error while using ActiveXObject, any solution to this.....
The exception for using ActiveXObject is for older Internet Explorer versions. I can't imagine you are developing for IE5/6 on a Mac, so if the line gives you errors, just remove it.
0

Iframe is going to be the best option for you neha

<html>
<head>
</head>

<body>
<font face="verdana,arial" size="3">
<div align="center">
<p>

<a href="http://www.altavista.com" target="iframe1">AltaVista.com</a> |
<a href="http://www.aol.com" target="iframe1">AOL.com</a> |
<a href="http://www.lycos.com" target="iframe1">Lycos.com</a> |
<a href="http://www.yahoo.com" target="iframe1">Yahoo.com</a>

<p>
<iframe
name="iframe1"
width="600"
height="400"
src="http://www.stackoverflow.com"
frameborder="yes"
scrolling="yes">
</iframe>
<p>

</font>
</div>

<!--
name="iframe1"
- Set all links to target the iframe1 name when you want the contents of the iframe to change from links on the originating page.

width="600" - Width of the iframe

height="400" - Height of the iframe * Width and height can be expressed in pixels or percent

src="http://www.yahoo.com" - Initial page that will fill in the iframe

frameborder="yes" - Border around the iframe is displayed by default

scrolling="yes" - Allow scrollbars around the iframe for navigation Vaild values are yes, no and auto

align="" - Valid entries are left and right left is set by default
-->

</body>
</html> 

Comments

0

if you want to do it easily and without an iframe you might find jQuery's load method helpful

$('#id-of-element-that-accepts-html-result').load('/url-that-returns-html-snippet.xyz', {
  //querystring parameters
  foo: 'bar',
  moo: 'par',
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.