Better alternative to an iframe?

前端 未结 8 1598
臣服心动
臣服心动 2020-12-05 03:20

I have a page with an iframe to feature the contents of the clicked tab. There are 3 tabs and 1 iframe. The sources of the contents relating to each tab clicked are formatte

8条回答
  •  攒了一身酷
    2020-12-05 03:21

    The HTML iframe is to be used to include/display non-template content, such as a PDF file. It's considered bad practice when used for template content (i.e. HTML), in both the SEO and UX opinions.

    In your case you just want to have a tabbed panel. This can be solved in several ways:

    1. Have a bunch of links as tabs and a bunch of div's as tab contents. Initially only show the first tab content and hide all others using CSS display: none;. Use JavaScript to toggle between tabs by setting CSS display: block; (show) and display: none; (hide) on the tab content divs accordingly.

    2. Have a bunch of links as tabs and one div as tab contents. Use Ajax to get the tab content asynchronously and use JavaScript to replace the current tab contents with the new content.

    3. Have a bunch of links as tabs and one div as tab contents. Let each link send a different GET request parameter or pathinfo representing the clicked tab. Use server-side flow-control (PHP's if(), or JSP's , etc) or include capabilities (PHP's include(), or JSP's , etc) to include the desired tab content depending on the parameter/pathinfo.

    When going for the JavaScript based approach, I can warmly recommend to adopt jQuery for this.

提交回复
热议问题