Search code examples
javascripthtmlapiuitabview

How to display, fetched data from API, in the html page?


I have an html page. Here, I am using tabview of Yahoo API. That is :

<div id="demo" class="yui-navset">
    <ul class="yui-nav">
        <li class="selected"><a href="#tab1" onclick="TopStories()"><em>Top Stories</em></a></li>
        <li><a href="#tab2" onclick="FinanceNews()"><em>Finance</em></a></li>
        <li><a href="#tab3" onclick="SportsNews()"><em>Sports</em></a></li>
    </ul>            
    <div class="yui-content">
        <div><p>Top Stories</p></div>
        <div><p>Finance</p></div>
        <div><p>Sports</p></div>
    </div>
</div>

In the onClickEvent the functions used, fetch data from Google NEWS>

function TopStories(){
location.href="http://www.google.com/news/search?aq=f&pz=1&cf=all&ned=in&hl=en&q=TopStories";
}
function FinanceNews(){
location.href="http://www.google.com/news/search?aq=f&pz=1&cf=all&ned=in&hl=en&q=Finance";
}
function SportsNews(){
location.href="http://www.google.com/news/search?aq=f&pz=1&cf=all&ned=in&hl=en&q=Sports";
}

But the Output is navigation to NEWS page. But, I want to display them as Tab Content.

What should I do ?


Solution

  • You can use iframe for this purpose .. see below example ,,

    Using Jquery tab, its always create a div where your result display. You have only way to open external link on your page using .

    <li><a href=ReturnIfram()><span>Google</span></a></li>
    

    href get a string which contain ifram like

    public string ReturnIfram()
    {
       return "<iframe src="http://google.fr"></iframe>"
    }
    

    try above in javascript see below example

    <html>
    <head>
    <script language="JavaScript" type="text/javascript">
    function makeFrame() {
       ifrm = document.createElement("IFRAME");
       ifrm.setAttribute("src", "http://developerfusion.com/");
       ifrm.style.width = 640+"px";
       ifrm.style.height = 480+"px";
       document.body.appendChild(ifrm);
    }
    </script>
    </head>
    <body>
    <p><a href="#" onMouseDown="makeFrame()">GO! </a></p>
    </body>
    </html>