0

My problem is as follows:
I designed a homepage and I Have a index (www.abc.com) site and a site with news(www.abc.com/index.html).

I tried to bring my headlines of all the news automatically to my index site. Therefore I programmed a small javascript function and it works locally but it doesn't work when it goes online.

The way I'm doing this is:

  1. Include an iframe (www.abc.com/index.html) in my index
  2. iframe is not visible
  3. Getting the structure of the iframe in my JS
  4. Picking out the information I need for the index
  5. Copy the data into my index

I know that I can't get data out from iframes which are not in my webspace, but this is in my webspace.

<iframe name="nf" id="newsframe" src="http://www.rossegger.at/news.html" 
style="visibility:hidden"></iframe>
<table id="news_table"></table>


function load_news() {    
    var con = document.getElementById("news_table");
    var frame = window.frames['nf'].document.getElementsByClassName('n');

    if(frame.length != 0)
    {
        con.innerHTML += "<tr><h2 color=white>NEWS</h2></tr><hr>";
        for(var i=0; i<frame.length; i++)
        {       
            con.innerHTML += "<tr>"+frame[i].textContent+"</tr><hr>";     
        }   
    }   
}

The problem is frame.length is always 0 (online)
offline the value has the right value.

Can anyone help me?

1
  • Do you mind mark my answer as the one that is the correct answer to your question? Commented Jan 23, 2013 at 9:48

1 Answer 1

2

You can't due to sandbox limitations in the browser. You have to approach the problem from a different angel, try fetch the iframe site with javascript and show it in a div. Or set up a rss page for your news site and get the headlines from that source.

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

6 Comments

I'm more or less a newbie in programming in JS has anyone a samplecode or something else?
@user1957388: sample code for what? RSS parsing in JavaScript?
I would prefer a solution where I can get out my Data from the Iframe via Javascript.
Or other easy ideas how I can get the data from my news site. All news items are in a separate table.
Ok I red something about this rss feeder methods. Am I right with the following statements: 1. I need an rss file on my root of my browser 2. I just need to update my rss file 3. On the next load of my homepage I can get automatically the content of the rss feed 4. I need a JS rss feed reader to get the information into my page. 5. I can read the rss file on my server via JS 6. Advantage is, that all visitors of my page can subscribe my news rss feed. What do I have to take into consideration at the implementing phase of this rss. Is it really that easy? Best regards.
|

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.