Vue.js blocks the use of iframes

I've come across a peculiar issue where I need to embed an iframe inside a Vue template and then be able to modify that iframe later. The code snippet below shows the simplified version of the problem:

<html>
  <body>
    <div id="app">
      <iframe id="testFrame" src="javascript:''" width="500" height="500"></iframe>
      <!-- This iframe is being inserted using the rails `yield` helper function. However, this is the MCVE representing our issue. -->
    </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.3/vue.min.js"></script>
    <script>

var doc = document.getElementById('testFrame').contentWindow.document;
doc.open();
doc.write('<html><head><title></title></head><body>Hello world.</body></html>');
doc.close();
new Vue({
  el: '#app'
});

    </script>
  </body>
</html>

The actual output of the iframe looks like this:

https://i.sstatic.net/jhM7Qm.png

However, what I aim for is to have it rendered as shown below:

https://i.sstatic.net/N4Wydm.png

What could be causing this issue, and how can I resolve it? (Note that this is just a basic example extracted from a much larger Rails application I'm developing.)

Answer №1

Performing XSS is not recommended as browsers do not support this action.

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

Unable to escape iFrame using Selenium WebDriver

I have successfully implemented the MathML Editor in my application, allowing users to enter text and print inside the editor. However, I am encountering an issue when trying to interact with elements outside of the editor, specifically the "Ok" button. Ho ...

Ways to retain specific div elements following the execution of .html(data) command

Imagine I have a div structured in this way: <div id = "foo" style = "display: grid"> <div id = "bar"> keep me! </div> </div> If I use JQuery's .html(data) method like shown below: $('#foo').html(data); when m ...

Importing an external JSON file into a ChartJs chart

As a newcomer to using libraries for drawing charts in JavaScript, I recently started playing around with Chartjs. However, I'm having trouble figuring out how to use getJson or any other method to load my json object and update the labels and data. I ...

Am I on the right track in my understanding of how document and viewport relate to mouse position in JavaScript?

After reviewing responses from a previous inquiry, it is evident that both pertain to the x and y coordinates of mouse positions. In relation to the document and In relation to the viewport. I have delved into an article on QuirksMode, yet I feel ther ...

How to pass arguments to the `find` method in MongoDB collections

I've been attempting to pass arguments from a function to the MongoDB collection find method. Here's what I have so far: async find() { try { return await db.collection('users').find.apply(null, arguments); } catch(err) { c ...

Challenges when using deep linking to URL with AngularJS ui-router

Recently, I encountered an issue after restructuring the folder organization of my AngularJS application. Although I believe this might be a distraction from the root cause, I moved a section of functionality to its own directory for better organization. A ...

Unable to render chart using angularjs-nvd3-directives

After developing a basic Angular - nvd3 project, I decided to utilize liveData.example from the angularjs-nvd3-directives Library on Github. To tailor it for my needs, I made enhancements to integrate with my REST API. Here is the REST API endpoint: http ...

Establishing the types of object properties prior to performing a destructuring assignment

Consider a scenario where a function is utilized to return an object with property types that can be inferred or explicitly provided: const myFn = (arg: number) => { return { a: 1 + arg, b: 'b' + arg, c: (() => { ...

Tips for sending a pre-made Vue component as a prop in Vue.js

Is there a way to pass an instantiated Vue Component as a prop to another component and then render it, similar to how it's done in React: <Button :icon=<IconComponent size="25" /> :link="http://wikipedia.org">Click her ...

Determine whether an object exists within another object and merge its value into the formatted object

When filling out a form, I have a formattedData object that holds a deep copy of the original data object. If a field in the form is changed, I must update the formatted data object with properties from the values object. To simulate this scenario, I crea ...

Submitting a Rails form with remote: true triggers a reload of the page

I have set up two controllers, home_controller and posts_controller, in my Rails 5.1 application using the scaffold tool. Currently, I am rendering the partial _form.html.haml in the index view of my home_controller.rb. Since I am using haml, the code look ...

Activate the dialog box exclusively after data has been submitted via the submit button on a form

My goal is to create a data saving functionality with a next button. After filling out the form, clicking on the next button triggers a popup dialog asking, "Do you want to submit your data?" To achieve this, I included the following code in my submit but ...

Leveraging prop data to create dynamic router links in Vue

I am attempting to develop a feature that will dynamically update links on ion buttons depending on the props received. So far, I have: <template> <ion-button router-link :to "`$/+ {{subLink1}}" shape="round">{{linkName1}}& ...

Using Javascript to set up a callback that alerts when a script file is done loading with the attributes "async" and "defer"

My app is loading the platform.js file asynchronously with the attributes of async defer. <script src="https://apis.google.com/js/platform.js?onload=onLoadCallback" async defer> </script> I am looking for a callback function that will alert m ...

Angular URL changes causing template flickering

Currently, I am in the process of developing a small application using Angular, but I am encountering an issue with template flickering. This problem occurs when one template is displayed briefly and then immediately switches to another. In my base templa ...

Error in NVD3 causing charts to be inaccurately rendered

While utilizing a stacked area chart in the Stacked display mode, there appears to be an issue with the shading under the graph, particularly on the left side of the displayed plot below. We are currently working with d3 v3.4.9 and nvd3 v1.1.15b. Do you ...

Sending data from a dynamically created PHP table to a modal

In my PHP-generated table, I have: <tbody> <?php $results = DB::select()->from('users')->execute(); foreach ($results as $user) { echo "<tr id='".$user['id']."'> <input type=&bs ...

Utilizing AngularJS to organize JSON data and display it in a table format

I currently have a JSON file that I am extracting data from using Angular.js. However, I would like to format the output in a table as depicted below. Here is my HTML and JavaScript code where I am retrieving the JSON data using Angular: https://i.stack. ...

Checkbox: Activate button upon checkbox being selected

On my webpage, I have a modal window with 2 checkboxes. I want to enable the send button and change the background color (gray if disabled, red if enabled) when both checkboxes are selected. How can I achieve this effectively? HTML: <form action="" me ...

Integrating Firebase into Vue.js 2 application using Vue CLI with webpack configuration

Recently, I started using vue-cli with a webpack template and I'm looking to integrate Firebase as my database for the Vue app. Here's how I imported Firebase into my app: Main.js //imported rest all required packages just dint mention here imp ...