Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to display clicked pages in single iframe

Hi friends,

I want to display clicked pages in single iframe,
I have single I frame,
Above this iframe i have website links to open in this iframe.

by default, there should be webpage inside iframe.

whenever above links are clicked it must display in this iframe.

one iframe for all clicked links.

Please help.
Thanks.
Posted

1 solution

You can change the src attribute of the iframe for each of the link. Iframe would load the content for those new locations and will display them.

For example, you can give this code a try,

HTML
<iframe src=""></iframe>
<a href="http://www.w3schools.com">Click me</a>


Inside the JavaScript script you can write this code to handle the events (navigation) and then display the document inside the iframe.

JavaScript
// Make sure you're having jQuery
$('a').click(function () {
  // prevent the page from navigating
  event.preventDefault();
  // load the page (located at the href of current hyperlink) inside the iframe
  $('iframe').attr('src', $(this).attr('href'));
});


This would handle all of the clicks on the hyperlinks, and will load the content of that page inside the iframe. Make sure that the page is visible (can be loaded) inside an iframe, for example, you cannot load Google's web page inside iframe.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900