简体   繁体   English

使用iframe或javascript将内容加载到div中

[英]Load content into div with iframes or javascript

I'm building a site for my band. 我正在为我的乐队建立一个站点。 I have the main page completed. 我的主页已经完成。 I'd like to load the other pages into the center div, #center_content without changing/reloading anything else on the page. 我想将其他页面加载到中心div #center_content中,而不更改/重新加载页面上的其他任何内容。 Should I do this with iframes? 我应该使用iframe进行此操作吗? JavaScript? JavaScript? PHP? PHP的? I'm not experienced in any of those, but they seem to be my options. 我没有任何经验,但似乎是我的选择。 Which one would be best and could someone provide a starting point or link to a tutorial that would fit what I'm trying to do? 哪一个最好,有人可以提供一个起点或指向适合我正在尝试的教程的链接?

Here's my site so far: http://img.photobucket.com/albums/v410/justice4all_quiet/ScreenShot2012-08-23at22259PM.png 到目前为止,这是我的网站: http : //img.photobucket.com/albums/v410/justice4all_quiet/ScreenShot2012-08-23at22259PM.png

Here's a jsFiddle: http://jsfiddle.net/BRPNM/ 这里有一个的jsfiddle: http://jsfiddle.net/BRPNM/

If the center content is small, then you could load all the content in one single page, then use inline navigation to show/hide the relevant parts. 如果中心内容很小,则可以将所有内容加载到一个页面中,然后使用内联导航显示/隐藏相关部分。 This is how I do it on this basic site (check out the right hand side buttons): http://usermanagedsolutions.com 这是我在此基本网站上执行的操作(请查看右侧按钮): http : //usermanagedsolutions.com

If the center content is important, then why would you not load a full page? 如果中心内容很重要,那么为什么不加载整个页面呢? With a good design, the parts that are common to all pages will be cached, and loading a new page won't take much longer than just loading the center content. 通过良好的设计,将缓存所有页面共有的部分,并且加载新页面不会比加载中心内容花费更长的时间。

If by "loading pages" you mean loading certain contents (like "about", "photos"), you can have all your content loaded but invisible (in divs set to display:none; ) and show these divs using jQuery .show() . 如果通过“加载页面”是指加载某些内容(例如“关于”,“照片”),则可以加载所有内容但不可见(在div中设置为display:none; ),并使用jQuery .show()

You can check how .show works here -see the demo-: http://api.jquery.com/show/ (you could also use .animate() to give the contents some effects). 您可以在此处检查.show的工作方式-请参见演示-: http : .animate()也可以使用.animate()赋予内容一些效果)。

This way your info will be indexed by search engines. 这样,您的信息将被搜索引擎索引。 You could also do it using only CSS, but in this case JS would be quicker and cleaner. 你也可以做到这一点只用CSS,但在这种情况下,JS会更快和更清洁。

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

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