Clicking on the iframe beyond the added content is no longer possible

I found a straightforward iframe text editor in this discussion thread. I've been attempting to create a "reply with quote" feature that adds HTML-tagged post content to the editor. However, I encountered an issue with making the iframe body clickable and allowing text entry outside of the grey appended div element. Is there a solution to re-enable clicking within the body?

HTML:

<div class='margin'><div class='content'><h4>wreeeeeeeeee dsfsd sdfd  sddfsfdsf</h4></div> <button id='reply'>Quote</button>
<div>
<a id="bold" class="font-bold">B</a>
<a id="italic" class="italic">I</a>
<select id="fonts">
 <option value="Arial">Arial</option>
 <option value="Comic Sans MS">Comic Sans MS</option>
 <option value="Courier New">Courier New</option>
 <option value="Monotype Corsiva">Monotype</option>
 <option value="Tahoma">Tahoma</option>
 <option value="Times">Times</option>
</select>

<br/>
<iframe id="textEditor" style="width:500px; height:170px;">
 </iframe> 
<input type='hidden' name='comments' id='comments' />    

<input id='submit'type='submit' value='submit'/>

Code:

    document.getElementById('textEditor').contentWindow.  document.designMode="on";
    document.getElementById('textEditor').contentWindow.  document.close();
    $("#bold").click(function(){

    if($(this).hasClass("selected"))
    {
        $(this).removeClass("selected");
    }else
    {
        $(this).addClass("selected");
    }
        boldIt();
    });
    $("#italic").click(function(){

    if($(this).hasClass("selected"))
    {
        $(this).removeClass("selected");
    }else
    {
        $(this).addClass("selected");
    }ItalicIt();
    });
    $("#fonts").change(function(){
    changeFont($("#fonts").val());
    });

function boldIt()
    {  
       var edit = document.getElementById("textEditor").contentWindow;
       edit.focus(); 
       edit.document.execCommand("bold", false, ""); 
       edit.focus();
    }

function ItalicIt()
     {  
        var edit = document.getElementById("textEditor").contentWindow;
        edit.focus(); 
        edit.document.execCommand("italic", false, ""); 
        edit.focus();
     }

function changeFont(font)
{
    var edit = document.getElementById("textEditor").contentWindow;
        edit.focus(); 
        edit.document.execCommand("FontName", false, font); 
        edit.focus();
}

$('#textEditor').contents().find('body').css("word-wrap", "break-word");

$('#reply').click(function(){
  var content = $(this).prev().html();
  $("#textEditor").contents().find("body").html('<div style="background:grey;color:#fff;border:1px solid #222">Reply to someone<br>'+content+'</div>');
});

(Apologies for not converting the example code back to jQuery syntax, as I encountered an undefined document error in my attempt)

Answer №1

Give it a shot

$('#textEditor').contents().find('body')
.css("word-wrap", "break-word")
.on("keyup", function(e) {
    var _break = $(e.target);
    if (_break.children().is(".break")) {
      $.noop();
    } else {
    _break.find("div")
    .after("<br class=break />");
    };
});

$('#reply').click(function(){
  var content = $(this).prev().html();
  var frame = $("#textEditor").contents();
    frame.find("body")
   .append('<div style="background:grey;color:#fff;border:1px solid #222">'
                          +'Reply to someone<br>'+content+'</div>');
    frame.find("div")
    .after("<br class=break />");
});

jsfiddle http://jsfiddle.net/guest271314/Kxmaf/568/

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

Unraveling the mystery: Retrieving data from various child components within a Vue parent component

Currently, I am in the process of constructing a view that includes a primary component called ContentComponent. This component acts as a container for a series of sub-components, each representing a form module. The list of forms include: EvaluationForm ...

Troubleshooting the unexpected behavior of the shareReply() method in Angular version 15

Utilizing the same API across 3 components can lead to duplicate HTTP calls. To prevent this, I decided to cache the response using shareReply() from RxJs so it can be reused wherever needed. Here's how I implemented it: api-service.ts getUsers(): Ob ...

Secure the anchor ahead of the table row

Currently, I am generating my code dynamically using PHP and assigning the ID attribute from the database to the anchor href. This is how it looks: PHP <table> <tr><th>ID</th></tr> <?php if ($stmt = $mysqli->prepare("S ...

Using the GET method in JQuery to send a JSON object

Trying to send a JSON object using the GET method. The code snippet used is: $.ajax({ url: "/api/endpoint", type: "GET", data: {"sort":"date"}, contentType: "application/json", dataType: "json", ...

Creating a search field in Bootstrap 4 that emulates material design, facing challenges with transition animations

I tried to create a material design search field using Bootstrap form input. While I was able to make it work, I noticed a small issue with the focus state. When I click inside the field, the underline animation runs smoothly. However, when I click outside ...

In certain cases, Bootstrap Grid may initiate a new row from the right side

Occasionally, when the last grid height differs from the others, a new grid will start from the right side in the next row. This is illustrated clearly in the image below. https://i.sstatic.net/Kjj25.jpg I have implemented <div class="col-xs-6 col-sm- ...

Ways to display distinct text boxes based on selected radio button?

Currently, I am working with JSP and have implemented an HTML form that includes a "Process" button at the top. When this button is clicked, it displays a form with two radio buttons - TestClient and TestServer. The form also contains a Submit button. If ...

elements positioned next to each other with gaps in between

Why is it so challenging to position two divs next to each other with a small space between them? I've attempted <div class="wrapper"> <div class="box" style="background-color: pink;">First Div</div> <div class="spacer">& ...

What steps can be taken to resolve the issue of "Access Denied: Invalid token, incorrect code"?

Assigned to me recently for a school project is a coding challenge that consists of various parts. The final task involves uploading to a private GitHub repository and submitting a completion request through a POST request under specific conditions. I hav ...

Creating a personalized and versatile table component with unique functionality: where to begin?

Looking to create a versatile table component that can adapt for both desktop and mobile versions. If the screen width is below 720px, it should display a table using div, ul, li elements with a "load more" button at the bottom. If the screen width i ...

Sending JSON Data over URL

I am facing a challenge with passing data between two HTML files. My initial solution involved sending the data through the URL using the hash and then parsing the link using JSON.parse(window.location.hash.slice(1));. This method worked for a few attempts ...

"PHP's isset function causes an infinite hang when trying to set a radio

When processing each question <input> set, some questions have radio button answers while others have checkboxes... Upon submitting, the data is inserted into the database $i = 1; while($i<6){ if(isset($_POST['radio' . $i])){ (MY ...

Utilize express compression in Node.js to compress JSON data from the REST API endpoint

I recently developed a small RESTful application using Node.js. I attempted to compress the JSON data returned by an API request using Express and compression, but unfortunately it did not work as expected. var express = require('express'); var ...

What is the best way to unselect a single checked checkbox within a multi-select widget?

I am looking for a way to automatically deselect a checked checkbox in a multiselect widget. My current approach involves triggering a click event on the checkbox and then sending an AJAX request to a PHP page to check for some results. If the result is su ...

Responsive Line Breaks in Bootstrap 4

I can't seem to find any information in the documentation to guide me in the right direction here. I'm hesitant to use columns as it could result in gaps between the text. Currently, I have the date displayed at the top of my website like this u ...

When integrating react-hook-form with Material-UI TextField in a form, an error occurs stating that "TypeError: e.target is undefined" when

Hey there, I stumbled upon something fascinating and could really use some assistance. Every time I attempt to perform an onChange, I run into the following error: TypeError: e.target is undefined. Here's a snippet of my setup: import React, { useE ...

How to deliver various static files in NestJS using different paths and prefixes?

I've set up static file serving for developer documentation using the following code: app.useStaticAssets(docsLocation, { prefix: "/docs/" }) Now I have another directory with more static content that I want to serve. Is it possible to serve from ...

JS setTimeout not postponing execution

Attempting to introduce a delay before an AJAX call. var delay = 2000; $("#c_name").on("keyup", function() { var entered = $(this).val(); if (entered.length > 1) { setTimeout(dosearch(entered), delay) } }); Struggling to implement a d ...

DTD syntax for specifying the attribute type of an image source file

After running a validation on my DTD file, I encountered an error that states the attribute type must be declared for element type profile. How should I go about editing my DTD file to resolve this issue? This is what my external DTD looks like: !ELEMENT ...

Preserve the captured image in PhoneGap iOS for later use

I am currently working on an IOS app using phonegap and have implemented the default camera API for users to take a photo for their profile picture. While the function works fine, I am facing an issue where the image captured by the user is not being save ...