Change the iframe (embed bootstrap) according to the navigation bar button

Asked

Viewed 1,100 times

3

Example:

Navigating:

   <ul >
    <li><a href="#"><span>INICIO</span></a></li>
    <li><a href="#"><span>FACEBOOK</span></a></li>
    <li><a href="#"><span>STACKOVERFLOW</span></a></li>
  </ul>

Embed:

<div class="embed-responsive embed-responsive-4by3">
  <iframe class="embed-responsive-item" src="index.php"></iframe>
</div>
<div class="embed-responsive embed-responsive-4by3">
  <iframe class="embed-responsive-item" src="www.facebook.com.br"></iframe>
</div>
<div class="embed-responsive embed-responsive-4by3">
  <iframe class="embed-responsive-item" src="/"></iframe>
</div>

What I need:

Always start with the initial frame index.php when the person clicks on facebook, open the frame facebook and so on

3 answers

2


You can also use the same frame, changing its destination.

The frame needs to have a name to be referenced.
In this example I put name="meuframe"

<iframe name="meuframe" src="http://terra.com.br"></iframe>

The links should be as target the frame name:

<ul>
  <li><a href="http://uol.com.br" target="meuframe"><span>UOL</span></a></li>
  <li><a href="http://binds.co" target="meuframe"><span>Binds.co</span></a></li>
  <li><a href="http://codepen.io" target="meuframe"><span>Codepen</span></a></li>
</ul>

That way, the frame loads with your src normal, and the links target the frame, changing its origin.

See working: http://codepen.io/anon/pen/NROzJd?editors=1000

1

See this example helps you:

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="keywords" content="jquery,ui,easy,easyui,web">
	<meta name="description" content="easyui help you build your web page easily!">
	<title>jQuery EasyUI Demo</title>
	<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/icon.css">
	<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
	<script>
		function addTab(title, url){
			if ($('#tt').tabs('exists', title)){
				$('#tt').tabs('select', title);
			} else {
				var content = '<iframe scrolling="auto" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>';
				$('#tt').tabs('add',{
					title:title,
					content:content,
					closable:true
				});
			}
		}
	</script>
</head>
<body>
	<div style="margin-bottom:10px">
		<a href="#" class="easyui-linkbutton" onclick="addTab('google','http://www.google.com')">google</a>
		<a href="#" class="easyui-linkbutton" onclick="addTab('jquery','http://jquery.com/')">jquery</a>
		<a href="#" class="easyui-linkbutton" onclick="addTab('easyui','http://jeasyui.com/')">easyui</a>
	</div>
	<div id="tt" class="easyui-tabs" style="width:400px;height:250px;">
		<div title="Home">
		</div>
	</div>
</body>
</html>

Example link

0

Another way of doing:

var iframe = $(".embed-responsive-item");

$("#menu li a").click(function() {
  iframe.attr('src', $(this).data('src'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="menu">
  <li><a href="#" data-src="index.php"><span>INICIO</span></a></li>
  <li><a href="#" data-src="www.facebook.com.br"><span>FACEBOOK</span></a></li>
  <li><a href="#" data-src="http://answall.com"><span>STACKOVERFLOW</span></a></li>
</ul>

<div class="embed-responsive embed-responsive-4by3">
  <iframe class="embed-responsive-item" src="index.php"></iframe>
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.