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

孤者浪人 提交于 2019-12-25 00:35:53

问题


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 ?


回答1:


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> 


来源:https://stackoverflow.com/questions/3518950/how-to-display-fetched-data-from-api-in-the-html-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!