JavaScript does not support clicking on an iframe

Here is some interesting javascript code that I came across:

function start1(dis,www){
    var visina = screen.availHeight;
    var content = '<a href="#" id="showRtb"><div id="showRtbn" style="position: fixed;text-align:center;left: 0px;width: 225px;height: 80px;top: 50%;z-index: 9999999;background: #E81515;cursor: pointer; border-radius:5px; margin-left:-15px;"> <iframe src="https://domain.com/hotel/2" style="border:0px #FFFFFF none;" name="myiFrame1" scrolling="no" frameborder="0" marginheight="0px" marginwidth="0px" height="100%" width="100%"></iframe></div>   </a>          <div id="rtb" style="width:100%; height:100%; opacity:0; position:fixed; box-sizing: border-box; left:0px; top:0px; z-index:99999999; display:none; background:rgba(0, 0, 0, 0.8)"><iframe src="'+www+'" style="border:0px #FFFFFF none;" name="myiFrame" scrolling="yes" frameborder="0" marginheight="0px" marginwidth="0px" height="100%" width="100%"></iframe><div id="hideRtb" style="background:#fff; cursor:pointer; top:15px; right:15px;  z-index:9999999; position:fixed; border-radius:25px;"><img style="width:50px; height50px;" src="http://i.imgur.com/QqlcQwu.png"></div></div>';

var newNode = document.createElement("DIV");  
newNode.innerHTML = content;
document.body.appendChild(newNode); 



   var rtb = document.getElementById("rtb"),
  timer = null;

document.getElementById("showRtb").addEventListener("click", function() {
  if (rtb.style.opacity != 1) {
    clearTimeout(timer);
    rtb.style.display = "block";
    timer = setInterval(function() {
      rtb.style.opacity = +rtb.style.opacity + .10;
      if (+getComputedStyle(rtb).getPropertyValue("opacity") >= 1) {
        clearInterval(timer);
      }
    }, 30)
  }
});

document.getElementById("hideRtb").addEventListener("click", function() {
  if (rtb.style.opacity != 0) {
    clearTimeout(timer);
    timer = setInterval(function() {
      rtb.style.opacity = +rtb.style.opacity - .10;
      if (+getComputedStyle(rtb).getPropertyValue("opacity") <= 0) {
        rtb.style.display = "none";
        clearInterval(timer);
      }
    }, 30)
  }
});




}

I encountered a problem with this code where the div with ID rtb doesn't show up when clicking on the link created by showRtb. Any ideas why?

When I replaced the iframe with an image, everything worked fine. But now that the iframe is back, it's causing issues. What could be the problem here?

My goal is to have the rtb div appear when clicking on showRtb...

LATEST UPDATE:

var content = '<div id="showRtb1" style="position: fixed;text-align:center;left: 0px;width: 225px;height: 80px;top: 50%;z-index: 9999999;cursor: pointer; border-radius:5px; margin-left:-15px;"><iframe src="https://domain.com/hotel/2" name="myiFrame1" scrolling="no" frameborder="0" marginheight="0px" marginwidth="0px" height="100%" width="100%"></iframe></div><a href="#" id="showRtb"><div id="showRtb" style="position: fixed;text-align:center;left: 0px;width: 225px;height: 80px;top: 50%;z-index: 99999999;cursor: pointer; opacity:0; pointer; border-radius:5px; margin-left:-15px;"></div></a><div id="rtb"><iframe src="'+www+'"  name="myiFrame" scrolling="yes" frameborder="0" marginheight="0px" marginwidth="0px" height="100%" width="100%"></iframe><div id="hideRtb"><img src="http://i.imgur.com/QqlcQwu.png"></div></div>';

Answer №1

Modify this:

var content = '<a href="#" id="showRtb"><div id="showRtbn"> <iframe src="https://domain.com/hotel/2" name="myiFrame1" scrolling="no" frameborder="0" marginheight="0px" marginwidth="0px" height="100%" width="100%"></iframe></div></a><div id="rtb"><iframe src="'+www+'"  name="myiFrame" scrolling="yes" frameborder="0" marginheight="0px" marginwidth="0px" height="100%" width="100%"></iframe><div id="hideRtb"><img src="http://i.imgur.com/QqlcQwu.png"></div></div>';

To become something similar to:

var content = '<div id="showRtbn"><iframe src="https://domain.com/hotel/2" name="myiFrame1" scrolling="no" frameborder="0" marginheight="0px" marginwidth="0px" height="100%" width="100%"></iframe></div><a href="#" id="showRtb">Show RTB</a><div id="rtb"><iframe src="'+www+'"  name="myiFrame" scrolling="yes" frameborder="0" marginheight="0px" marginwidth="0px" height="100%" width="100%"></iframe><div id="hideRtb"><img src="http://i.imgur.com/QqlcQwu.png"></div></div>';

Delete the iFrame within the link tags (<a>..</a>) and you can make its containing <div> as hidden. REMARK: I've taken out your styles. It is advisable to move them into a stylesheet

JS:

document.getElementById("showRtb").addEventListener("click", function() {
  rtb.style.display = "block";
  console.log("clicked");
});

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

execute the execCommand function following an ajax request

I am currently developing a WYSIWYG editor and encountering an issue with image handling using execCommand. Here is a simplified example of my page structure: <div id="buttons_panel"><input id="img_submit" type="button"/></div> <div ...

Collaborating and monitoring data between controllers

A unique challenge has arisen as we implement a tree-style navigation element that must communicate with other directives/controllers. The main objectives are: Keep track of the current selection, Detect when the row selection changes. The task at hand ...

Updating MongoDB collections in Mongoose with varying numbers of fields: A step-by-step guide

Updating a mongodb collection can be challenging when you don't know which fields will be updated. For instance, if a user updates different pieces of information on various pages, the fields being updated may vary each time. Here is my current appro ...

utilizing services across multiple controller files

Service - optionService.js controllers - app.js & welcomeCtrl.js & otherCtrl.js app.js var app = angular.module('mainapp', ['mainapp.welcome','optionServiceModule']); app.controller('mainappCtrl', functio ...

Utilizing Javascript to retrieve the current Controller and Action in Rails

Is it possible for JavaScript to determine the current controller and action in Rails? I had the idea of creating a hidden container to store the current controller and action, but I'm curious if there is a specific JavaScript function for this purpo ...

Next.js Image staying at the forefront

Currently, I am utilizing Tailwind CSS to style my Next.js website and incorporating the Next.js Image element for an image on the page. My goal is to display a modal over the existing page without completely blacking out the background; instead, I want i ...

When a word is found in the key of an object

Here is an example of the object I am working with: {"status":200, "success":true, "result": [ {"Description":"", "Year":"", "Price/STK":"", "Main Cat":"Fruits"} ] } I have multiple lists that I need to make use of, and the Price key can take different ...

Automatically scrolling through a nested list in ReactJs

I have a chat list integrated into my web application. The entire webpage is scrollable, as shown in the image at the bottom. I would like the messages list to automatically scroll to the bottom whenever a new message arrives. To achieve this, I created a ...

Struggling with a persistent Jquery AJAX problem despite numerous attempts to resolve it

<table class="table table-striped"> <thead> <tr> <th>Choose</th> <th>>Location</th> <th>Topic</th> & ...

Sending data from configuration to factory in AngularJS and UI Router

Trying to perform a search in an http call with a dynamic value based on the current view. The factory setup is as follows: .factory('SearchService', ['$http','$filter', function($http, $filter) { var service = { get ...

What is the best way to retrieve a parameter in jQuery ajax?

Seeking assistance with retrieving the parameter sent via ajax... url: test.htm?a=1&b=2&c=3 I am trying to access the value of b. ...

Summoning within a rigorous mode

I am facing an issue with my configuration object: jwtOptionsProvider.config({ tokenGetter: (store) => { return store.get('token'); }, whiteListedDomains: ['localhost'] }); In strict mode, I ...

A layout featuring a grid design that includes spacing and gutters between items, however, there is no spacing between the items

I am looking to create a grid layout where each child element represents an individual grid square. However, I am facing an issue with spacing between the children and the parent container, which is not desired. How can I eliminate this unwanted space? U ...

I am attempting to achieve a smooth transition effect by fading in and out the CSS background color using JQuery and AJAX

Can anyone help me with my issue related to using Ajax to fadeIn a background color in beforeSend and fadeOut in success? I seem to have made some mistakes but can't figure out what went wrong. var data={ ...

Tips for resolving alignment issues in a chat box:

I am currently working on adjusting the alignment of my chat box app. I have placed 3 div elements with the class .bubble inside a div with the class .chatlines, but they appear to be clustered together instead of aligned properly. It's challenging to ...

What is the best method for arranging various react components in sync?

I am striving to achieve a specific style. My current code looks like this: <Box display="flex" flexDirection="row" alignItems="center" width={1}> <Box flexGrow="1"> <Typography variant="h6 ...

Error: Encountered an unforeseen symbol '<' during AJAX request

I'm in the process of creating a JavaScript array to help me determine the online status of various streams. However, whenever I attempt to alert the output, I keep encountering an unexpected token '<' error at line 1 of my document. It&a ...

Determining the Existence of a Model in Backbone/Marionette

I've built a simple backbone application, but I'm struggling with a more complex check that needs to be performed. Below is my code. I'm creating a list of chat participants. Eventually, I'll pass this list into a JavaScript function. ...

Resounding achievement following the completion of the upload

I'm looking to display the message "success" on the same page as my form if it uploads correctly. I am new to PHP and not sure how to achieve this. Can anyone help? index.php <form action="upload" method="POST"> <input name="field1 ...

The functionality of Directive hinges on the use of a template

I am exploring a more web-component approach to using Angular. As part of this, I have developed an http-request directive with url and response attributes. The implementation is successful, but I find that my directive relies on a template unnecessarily. ...