Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use a DIV instead of an iFrame so that content looks like in the same page?

I have a web page, I need part of the content separated to an individual page, but not use iframe. Just like to know if it is possible use div instead of iframe and works as it in the same page(With js base code or php code is cool).

I'd need the whole content of <div class="row-fluid">..</div> to be an individual html, but not use iframe, I will need a div instead of iframe, and make it works like just as in one page.

like image 606
bard Avatar asked Dec 18 '13 14:12

bard


People also ask

Can we use div instead of iframe?

It is able to integrate itself on the webpage using a div instead of an iframe when using IE. (Unfortunately it akways uses iframe for Gecko.) Having the editor integrate on the webage using div is huge convenience since it then perfectly integrates with the page's CSS rules.

What can be used instead of iframe?

Use the embed Tag as an Alternative to Iframe in HTML The embed tag is similar to the object tag, and it is used for the same purpose. We can embed various external resources in our web page using the embed tag. We can embed media like PDF, image, audio, video, and web pages.

What is the difference between div and iframe?

A div and an iframe no matter what the position type of the div are not equivalent. An iframe has a src attribute that lets it load external or other internal html pages within your current page. You cannot do this with a div by itself. There are ways around this, however it sounds like your just showing a modal popup.

Why you shouldn't use an iframe?

Iframes Bring Security Risks. If you create an iframe, your site becomes vulnerable to cross-site attacks. You may get a submittable malicious web form, phishing your users' personal data. A malicious user can run a plug-in.


1 Answers

With PHP you can include a page inside your code inside a specific division.

for example inside index.php:

<div>
  <?php include('page2.php'); ?>
</div>

and inside page2.php you have:

<span>Hello World</span>

The result would be:

<div>
  <span>Hello World</span>
</div>

If what you want to achieve needs to be in the front-end as the user navigates through your site; that is after a click is made to an element and you don't want to change to another page, then AJAX is your option. this example is with Jquery:

$('.clickme').click(function(){
  $.ajax({
    url:'page2.php'
    success:function(msg){
      $('#insert_div').html(msg)
    }
  });
});

HTML:

<span class="clickme">Get Page 2</span>

<div id="insert_div">
  <!-- Page 2 will be inserted here -->
</div>

Another solution is Jquery load() as many have posted:

$('.clickme').click(function(){
  $('#insert_div').load("page2.php");
});
like image 161
multimediaxp Avatar answered Sep 18 '22 19:09

multimediaxp