简体   繁体   English

我可以直接导航到iframe的本地内容,但仍加载到iframe中吗? 加上书签?

[英]can i navigate to iframe's local content directly, but still loaded into iframe? bookmark it?

I have an iframe in my index.html. 我的index.html中有一个iframe。 Content is loaded into it through a menu bar: 内容通过菜单栏加载到其中:

...
<iframe name="iframe-main" id="iframe-main" src="content.html" frameborder="0">
</iframe>
...
/* menu bar */
<a href="impressum.html" target="iframe-main" name="impressum">Impressum</a>
...

The target url to be loaded into the iframe has a somewhat reduced header: 要加载到iframe中的目标网址的标头有所减少:

<html>
<head>
<link rel="stylesheet" type="text/css" href="css/default.css" media="screen"/>
</head>

<body style="margin: 0; border: 0; padding: 0;">
....

The iframe's url or some identifier does not show up in the url bar. iframe的网址或某些标识符未显示在网址栏中。 i have tried adding name tags to the link loading the iframe but the url bar always shows the base url. 我尝试将名称标签添加到加载iframe的链接中,但网址栏始终显示基本网址。 is it possible to solve this (preferably html only, but i'm open to beginner-friendly js and php)? 是否有可能解决这个问题(最好仅使用html,但我欢迎初学者使用的js和php)?

Edit: I just noticed the iframe's history is stored in my browser history, so i can go back and forth and the iframes are loaded into the main window, but i cannot access it through the url bar (type a direct address) nor bookmark it. 编辑:我只是注意到iframe的历史记录存储在我的浏览器历史记录中,所以我可以来回移动,并将iframes加载到主窗口中,但是我无法通过网址栏(输入直接地址)访问它,也无法对其添加书签。 That would be the feature I want. 那就是我想要的功能。
maybe some php snippet? 也许一些PHP片段?

After some research I realised that iframes are not suitable for what I want, and I have to look at the problem from the other end. 经过一番研究,我意识到iframe不适合我想要的功能,因此我必须从另一端着手研究问题。 I ended up using php includes. 我最终使用了PHP include。 This basically injects the always-the-same menu bar into the pages with varying content, before serving them out. 在将它们提供出去之前,这基本上将总是相同的菜单栏注入到内容变化的页面中。 I guess I thought the iframe solution would be more bandwidth-friendly but I can't tell the difference. 我想我认为iframe解决方案将对带宽更加友好,但我无法分辨出差异。
This tutorial got me on the right track and 本教程使我走上了正轨,
This one explains how to do it, both with Server Side Includes and with PHP. 这一篇解释了如何使用Server Side Includes和PHP。 It says SSI is easier and simpler than PHP but I really don't see why, at least not in this situation. 它说SSI比PHP更容易和更简单,但是我真的不明白为什么,至少在这种情况下不是这样。
Since my project hasn't grown too much yet, the changes were very quick to implement. 由于我的项目还没有发展太多,因此更改很快得以实施。
I tested this on 2 servers and both SSI and PHP were available on both. 我在2台服务器上对此进行了测试,并且SSI和PHP都可以使用。
As a bonus, I got rid of those frame-resizing java scripts! 另外,我摆脱了那些框架大小可调的Java脚本!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM