Jump to content

Recommended Posts

I have a small project, which needs to read a status from an online page.

 

Basically, I need a script to search for a certain tag ID from say www.foo.com/page1.html

 

What I intend to do is get the ID of a certain tag and then save the inner HTML of it into a variable.

 

Any ideas? I tried loading the page in an iFrame and trying JS to get an ID but fails.

 

This is what i tried.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<script type="text/javascript">

function getContentFromIframe(iFrameName) {

  var myIFrame = document.getElementById(iFrameName);

  var content = myIFrame.contentWindow.document.body.innerHTML;

  var status = content.getElementById('AREA:222_4');

  alert(status);

}

</script>

</head>

 

<body>

<iframe id="emap" src="http://emaplin3.foo.com/page1.html">

</iframe>

<input type="button" value="Get Status" onclick="Javascript: getContentFromIframe('emap')" />

</body>

</html>

 

Now I'm lost.

getElementById is a method of the document object. Should be:

 

var content = myIFrame.contentWindow.document;

 

Edit: although you might want to consider changing the name of the variable, as it's a little misleading now.

Thanks for the Reply, but it still doesn't work.

 

What I am trying to do is, say i got a page, index.html, then i got another page content.html.

I have an iframe in index.html which contains content.html. i also have a button in index.html which when clicked needs to return an id from a tag inside content.html.

 

I am trying to make a script which gets the innerHTML of a tag with the id provided by the user inside content.html.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.