The issues of cross-origin domains arise when utilizing iframes with src links originating from the server side

Encountering a cross-origin domain issue, receiving the following error while working with an iframe:

candidateInterviewCtrl.js:39 Uncaught SecurityError: Blocked a frame with origin "http://localhost:9000" from accessing a frame with origin "http://localhost:4000". Protocols, domains, and ports must match.

Below is the HTML code snippet:

<div ng-class="{'col-xs-6': myVar=='something'}">
<div class="panel panel-default panel-height" ng-repeat="candidateInfo in aCandidateDetails track by $index">
    <div class="panel-heading header-background">
        <div stop-watch time="xyz" name="candidateInfo.name" time-of-interview="candidateInfo.doi" class="stop-watch"></div>
        <div class="row">
            <div class="col-xs-2"><a style="cursor:pointer" class="pull-right">{{candidateInfo.name}}</a></div>
            <div class="col-xs-offset-9"><a style="cursor:pointer" ng-click="fnVar(candidateInfo.name, candidateInfo.filepath)" data-toggle="collapse" data-target="{{'#'+toggle}}">{{candidateInfo.name}} resume</a></div>
        </div>
    </div>
</div></div>
<div id="{{toggle}}" class="collapse" ng-class="{'col-xs-6': myVar=='something'}" ng-if="checkVar">
<iframe width="100%" height="600px" ng-src="{{getIframeSrc()}}" onload="resizeIframe(this)"></iframe></div>

The src link is provided from the server side through the controller.

Here is the controller code snippet:

angular.module('hrPortalApp')
.controller('candidateInterviewCtrl', function($scope, $state, $sce, getCandidateInterviewListService) {
    getCandidateInterviewListService.fnGetCandidateDetails("xyzzy").then(function(response) {
        $scope.aCandidateDetails = response;
        console.log(response);
        $scope.toggle = "accor"
    });
    $scope.fnVar = function(name, filepath) {
        $scope.file = filepath;
        $scope.checkVar = !$scope.checkVar;
        if ($scope.checkVar) {
            $scope.myVar = "something";
        } else {
            $scope.myVar = false;
        }
    };
    $scope.fnInterviewView = function(name) {
        $state.go('main.Topics', {
            "candidateDetails": $scope.aCandidateDetails,
            "name": name
        })
    };
    $scope.getIframeSrc = function() {
        return 'http://localhost:4000/' + $scope.file;
    };
    window.resizeIframe=function(obj){
        obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
    }
});

Seeking assistance on resolving this cross-domain issue despite implementing CORS on the server side.

Any suggestions or help would be greatly appreciated.

Answer №1

Your server is currently configured with cross-site origin restrictions in place. The error you are encountering is due to attempting to request an iframe resource from localhost:4000 while your current location is localhost:9000. To resolve this issue, either modify the request to come from localhost:9000 or disable the cross-origin restrictions altogether.

Answer №2

Your setup involves two different domains: http://localhost:9000 and http://localhost:4000. Due to the implementation of the same-origin policy, any attempt by a script to access a frame from a different origin is blocked by most browsers. For further details, please check out this detailed explanation on StackOverflow.

Nevertheless, there is a workaround available which involves disabling the same origin policy in your browser.

  1. If you are using Chrome, follow this guide: disabling same origin policy in Chrome.
  2. For Firefox users, here's how to disable it: disabling same origin policy in Firefox.

Keep in mind that this solution will only apply to your local browsing experience.

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

Issue: unable to inject ngAnimate due to uncaught object error

Whenever I attempt to inject 'ngAnimate' into my app, I encounter issues with instantiation. Here is the code snippet in question: var app = angular.module('musicsa', [ 'ngCookies', 'ngResource', 'ngSanit ...

Automatically update certain attributes of an object with Spring MVC's auto-refresh feature

Currently, I have a table in JSP where I am populating all object attributes using Spring MVC. The backend is providing a list of DTO's which are then being added to the ModelView. In the JSP, we iterate through this DTO list and display it in the tab ...

Utilizing Firebase authentication to sign in via phone number in conjunction with Express on Node.js

Encountering an issue while implementing backend Firebase Authorization. After thoroughly reading the documentation (https://firebase.google.com/docs/auth/web/phone-auth), I came to understand that Authorization requires two steps: send phone send code ...

Executing asynchronous jQuery AJAX requests using the async/await syntax

Currently, I have a situation where I am using 3 ajax call methods in succession. However, there needs to be a delay between the second and third ajax calls. Initially, I used "async:false" in the second ajax call and everything worked smoothly. But later ...

Angular 2 Error: AOT issue with base64 function not recognized

Currently, I'm attempting to compile my project using AOT. When I execute the command ngc -p tsconfig-aot.json Initially, it creates an aot folder with ngFactroy. However, when I modify the main ts file (as specified in the Angular documentation) to ...

Extract data from an ajax request in an AngularJS directive and send it to the controller

I am currently experimenting with integrating the jQuery fancy tree plugin with Angular. The source data for the tree is fetched through an ajax call within my controller. I am facing a challenge in passing this data to my directive in order to load the tr ...

Transferring form data to a PHP script with the help of JavaScript/jQuery

Struggling to figure out how to pass form values to a PHP script using JS. The PHP script is functioning correctly by saving the data into a text file with additional information such as IP and Date/Time. Despite being a simple issue, my lack of JS knowl ...

Implement VueJS functionality to prevent form submission upon submission and instead submit the form upon keyup

My form has the following structure: <form id="myForm" action="/searchuser" method="POST" @submit.prevent="onSubmit(inputValue)"> <div class="field"> <label class="label">Name</label> <div class="control"> ...

Error in Vue Vuelidate appearing when form is submitted with empty data property

I have been working on some basic validation for required fields and minimum length. The problem arises when I submit a network request for data insertion, the validation works perfectly fine. However, after the network call, if I try to make my text fie ...

"Despite successfully clicking on the menu with Selenium WebDriver, no action or change occurs on the webpage

Currently, I am in the process of writing a selenium C# test script for an older "infragistics" webpage, which I must admit, is not something I am very familiar with. The challenge I am facing is that the page does not provide many options for referencing ...

Comparing ngOnInit() and $onInit = () => { } - what sets them apart?

I've been diving into AngularJS and had a question about the difference between $onInit = () => {} and ngOnInit() { } in terms of functionality. Can anyone shed some light on this for me? ...

Display a particular div when a specific image is present within another div

I'm currently working on a task, but I'm having trouble with it. If I have an image called smiley.png within a div with the class "selected." <div class="selected" style=""><img width="25" height="24" src="images/smileys/smiley.png ...

Efficiently condense a sequence of ones and zeros into a more compact format, then effortlessly revert it back to the original sequence without any changes. Each time

I've been exploring different approaches in NodeJS and plain JavaScript to improve this task. Currently, I have developed some functions that count the repetition of characters, but I'm curious if there are more efficient methods or potential en ...

Is it more beneficial to keep a function inside or outside another function if it is only being used within it?

Within the topic at hand, I have a function structured as follows. There are numerous auxiliary functions declared within this function (twice the amount shown in the example) because they are solely utilized by this function. My query is: should I extrac ...

What is the cost associated with using the require() function in an Express.js application?

I have a web application built with Express.js that serves one of my domains. The structure of the app.js file is as follows: var express = require('express'); var app = express(); // and so on… To incorporate one of my custom functions in t ...

Using the ng-app directive value with HTML and CSS can sometimes cause issues and the styles may not apply

angular.js:38 Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=mainapp&p1=Error%3A…ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A19%3A463) <body ng-app=""> It was working fine unt ...

Press the div using JavaScript and jQuery

Is it possible in JavaScript to automatically click on a hidden div once it is displayed? For instance, imagine we have a div with the style "display:none;" like so: <div style="display:none;" id="button">Hello World</div> Once this div&apos ...

The Material UI Drawer is fading into the background instead of smoothly sliding into view

Seeking guidance as a novice in SD, I am dedicating my free time to honing my skills. Any advice is appreciated, but please explain it as if I were a child. My current endeavor involves making the Drawer Component feature functional and customizing it to s ...

Can you guide me on how to establish a cookie within a selenium webdriver javascript script?

I am trying to figure out how to set a cookie using a basic webdriver script: WDS.sampleResult.sampleStart(); //WDS.driver.manage().addCookie(new Cookie("connect.sid", "s%3AeexeZcd_-S23Uh30e3Dmd4X9PskWF08s6m5hDurDa5Jj66SupmmiqvKEjAg6HGigl0o0V%2B9R7m4", ...

The onPlayerReady function in the YouTube API seems to be experiencing a delay and

After following a tutorial on integrating the YouTube API into my website, I encountered difficulties trying to play a YouTube video in fullscreen mode when a button is pressed. Despite following the provided code closely, I am unable to get it to work as ...