开发者

Linking to a page within an iframe

On a website I am working on, we have a news page. On the news page is an embedded iframe for the news articles. The site开发者_如何学Python also has a sidebar on every page with three of the featured news story titles in it. Is it possible to make these news stories both lead to the news page and then open up the appropriate related news article within the iframe? The site is set up in ExpressionEngine, so the linkes will need to be set up so that the client can change the news link and the corresponding URL.

I know if I link to the news story and then have target="news-window" (and news-window on the iframe) it will open up in the iframe when you are on the news page. The issue is when you are on a different page (and so the iframe can not be found), it opens up in a separate window. I need to make it go to the news page first and then execute the href. I think some simple jquery should do it, but I am not sure exactly where to begin. Any help would be great.


From the answer below, I have adjusted my code to look as follows:

Sidebar link: <a href="/news#id=1930">Link Here</a>

On News page:

 <?php if ( isset( $_GET['id'] ) ) : ?>
    <iframe src="http://www.newsite.com/news/abunchofletters&ClientArticleID=<?php echo $_GET['id'] ?>" width="680" height="380" scrolling="yes" frameborder="0">
    </iframe>
  <?php endif; ?>

On the RSS feed the article ID is called by "&ClientArticleID." Now the link works and the iframe works, but when you click on the link it still only leads to the News page and not the specific article within the iframe. I am using the # tag instead of a ? because it the ? wasn't working. Maybe because my pages don't end in .php because they are through EE. Any thoughts?


I had to do this once, when we needed to show a page from another site in an iframe. If you call the news page with a URL like this:

http://domain.com/news.php?id=743

where id refers to the news item ID in the database, you can then put code in the news.php page:

<?php
if ( isset( $_GET['id'] ) ) : ?>
<iframe src="http://www.othersite.com/article.php?id=<?php echo $_GET['id'] ?>">
</iframe>
<?php endif; ?>

This will dynamically load the article into the iframe from the ID specified in the query string.


Give the iFrame a name, then give the link a target of the name of the iFrame.

If the name of the iFrame was 'mypage', then the code would look like this:

<iframe src="http://example.com" width="500px" height="500px" name="iframe"></iframe>
<a href="http://doc.jsfiddle.net/" target="iframe">Go to JSFiddle Docs in the iFrame</a>

See it at http://jsfiddle.net/zJC6v/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜