Is it possible to target an iframe and display text simultaneously?

Trying to create a unique menu that interacts with an iframe and displays text in a separate div upon clicking.

Example:
• Menu item 1 clicked.
• "https://wikipedia.org" loads in the iframe.
• Address of the wikipedia page displayed in a different div.

Managed to display text as desired, but struggling to target the iframe simultaneously.

Considering using query for better functionality?

Any assistance would be greatly appreciated!

(A JavaScript function is used to turn the clicked link red).

var Lst;

function changecolor(obj) {
    if (Lst) Lst.style.color = "#663399";
    obj.style.color = "red";
    Lst = obj;
}
a:link {
  text-decoration: none;
}
a:visited {
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
a:active {
  text-decoration: underline;
}
.menu {
  font-size: 13px;
  width: 260px;
  height: 350px;
  left: 8px;
}
#tabs p {
  display: none;
  font-size: 13px;
}
#tabs p.tab1:target {
  display: block;
}
#tabs p.tab2:target {
  display: block;
}
#tabs p.tab3:target {
  display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<body>

  <div id="tabs" class="menu">

    <a href="#tab1" class="nav-tab tab1" onclick="changecolor(this)">
Menu item 1<br><br></a>

    <a href="#tab2" class="nav-tab nav-tab-active tab2" onclick="changecolor(this)">
Menu item 2<br><br></a>

    <a href="#tab3" class="nav-tab nav-tab-active tab3" onclick="changecolor(this)">
Menu item 3<br><br></a>

    <p id='tab1' class='tab1'>
      <a href="https://www.wikipedia.org">"https://www.wikipedia.org"</a>
    </p>

    <p id='tab2' class='tab2'>
      <a href="http://dictionary.reference.com">"http://dictionary.reference.com"</a>
    </p>

    <p id='tab3' class='tab3'>
      <a href="http://www.thesaurus.com">"http://www.thesaurus.com"</a>
    </p>

  </div>

</body>

Answer №1

My approach to achieving this is through the utilization of JQuery:

$("a").click(function(){
   $("iframe").attr("src", $($(this).attr("href")).find("a").attr("href"));
});

You can view the JSFiddle demonstration here

(Please be aware that the additional links besides Wikipedia are not loading independently and are also not appearing in the iframe. You might want to consider using alternative links instead :) )

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for identifying a scroll down gesture on a touch device with jQuery

I have a method for infinite scroll that is triggered like this: $(window).on('scroll resize load', function() { // execute the infinite scroll method }); It is triggered by these events: scroll resize load However, it does not seem to ...

How can I make the lines of my drawer thicker in Material UI?

Currently, I'm in the process of implementing a left-side navigation bar for a web application I'm developing. The main challenge I'm facing is customizing the styles as desired when using the Drawer component. Specifically, I'm aiming ...

Notifying with Jquery Alert after looping through routes using foreach loop

I am trying to create a jQuery alert message that displays after clicking on a dynamically generated button in the view using a foreach loop. The issue I am facing is that only the first button in the loop triggers the alert, while the subsequent buttons ...

The {shade} of the code has been modified within brackets

Ever encountered your code's colors abruptly changing to red and green in the middle of an HTML page? My editor is Brackets, and while it doesn't pose any issues, it's really bothersome and makes the code difficult to read: Take a look at t ...

Problems with Angular UI Router: Functions not functioning properly within the template

Currently, I am delving into the realm of Angular UI Router in order to effectively manage different sections of my application. If you'd like, check out this plunkr (http://plnkr.co/edit/KH7lgNOG7iCAEDS2D3C1?p=preview) Here are some issues that I&a ...

An unusual outcome occurred while attempting to duplicate the text

After copying the letter A, I noticed that an empty string is being logged to the console instead of the expected A. However, when I paste, the console does successfully log the letter A. document.addEventListener('copy', handler); document ...

Exploring the Functions and Applications of Headers in Javascript

After completing a project which involved updating a JSON database from the front end, I am still uncertain about the role of the headers within the AxiosConfig. Can you explain the difference between using axios with and without it? For instance: What s ...

Unable to get the Gtranslate function to function properly within the drop-down menu

Currently, I am using Gtranslate.io languages on my website with flags displayed without a drop-down menu. Everything is running smoothly but now I am looking to enhance the user experience by placing the flags inside a drop-down list. I want English to ...

I'm having trouble getting rid of this stubborn loader on the website

I am currently utilizing the following template: . My objective is to eliminate the preloader progress bar that displays the loading progress of the page in percentage. The files associated with this preloader are as follows: Loader CSS File - www[dot]the ...

Mastering the art of concurrent Ajax requests using jQuery for an advanced Posting and Commenting system

In my Asp.net MVC project, I have successfully implemented a post and comment mechanism. The posts and comments are stored in different tables in the database. Additionally, using Ajax requests with jQuery, I can retrieve comments from the database and dis ...

Refreshing Resteasy utilizing an Ajax POST method

My Ajax post request is not working with Resteasy. I am not getting any errors in Java, but in the browser I see this message: event.returnValue is deprecated. Please use the standard event.preventDefault() instead. OPTIONS https://localhost:8081/TestRes ...

What is the best method for executing an HTTP request to retrieve the complete source page if certain aspects are loaded through JavaScript?

I am trying to retrieve the HTML webpage from . However, a portion of the HTML file is loaded through JavaScript. When using HTTP.jl to fetch the webpage with HTTP.request(), I only receive the part of the HTML file that was loaded before the execution of ...

What is the process for specifying the content type as application/json in an Ajax request?

Do you have a smart contract named GovtContract that functions properly when utilizing curl commands? $curl -X POST -H "Content-Type: application/json" localhost:3000/govtcontract/set -d '{"value":"5"}' | jq $curl -X GET -H ...

Are you looking to work with an ASMX web service and navigate JSON utilizing JavaScript or

Currently, I am using asmx to fetch data from a database. public class TestPage1 { public int UserID { get; set; } public string UserName { get; set; } public string Password { get; set; } public string FirstName { get; set; } public ...

Add the element just a single time

My e-commerce template is designed to be responsive with a navigation bar that adjusts to the window size. When the window is resized below a certain point, the navigation bar stacks vertically. The menu items that have submenus are marked with an "expand ...

Dragging items in the horizontal list of Knockout-Sortable causes them to be pushed vertically

For my application development using knockout.js, I am implementing knockout-sortable to create drag-and-drop sortable lists. The setup involves a vertical list with each item containing a horizontal list. While the vertical lists are functioning properly, ...

Personalize the color and icon of the checkbox marks in sapui5

I'm trying to customize the color of the tick on a UI5 checkbox. After inspecting the CSS, I noticed that it can be modified using the ::before selector: To target the checkbox, I added a class called .accept and defined it in the CSS file like this: ...

Troubleshooting problem with custom Angular directive integrating KineticJS

Hey there, I'm currently working on putting together a KineticJS application in Angular and need to resolve a minor issue. While following an example for setting up a draggable shape in AngularJS using KineticJS from this link: , I encountered this er ...

Avoid the automatic scrolling of a datatable to the top when clicking on a button within a column using jQuery

Is there a method to stop the datatable from automatically scrolling to the top when any of the buttons is clicked? ...

Employing bootstrap to include oversized images within a compact, fixed div

I am facing an issue with image responsiveness in the middle row of my layout. Despite using Bootstrap 4 and applying classes like img-fluid, the images in my #fullColumn area do not resize properly. The images are dragged into this area by users and are ...