2

After some research I am able to send the data to Server and get response however, on response I am getting error

Blocked a frame with origin "http://localhost:3001" from accessing a frame with origin "http://localhost:3010". Protocols, domains, and ports must match.

and

Uncaught DOMException: Blocked a frame with origin "http://localhost:3001" from accessing a cross-origin frame.

How to implement this check in angularjs part in ckeditor to get the url and set the url in the

AngularJs : localhost:3001

index.html

<script>
        window.addEventListener("message", receiveMessage, false);

        function receiveMessage(event)
        {
            var origin = event.origin || event.originalEvent.origin; // For Chrome, the origin property is in the event.originalEvent object.
            if (origin !== "http://localhost:3010" || origin !== "http://example.com")
                return;

            // ...
        }
    </script>

tmpl.html

<div id="a" ckeditor="vm.options" ng-model="vm.textInput" ready="vm.onReady()"></div>

controller.js

where API_ENDPOINT = localhost:3010
vm.options = {
            language: 'en',
            allowedContent: true,
            entities: false,
            filebrowserImageUploadUrl : API_ENDPOINT.url+'/ckeditor/pictures' 
        };
        vm.onReady = function () {
            // ...
        };

server side : localhost:3010

editor.js following the route /ckeditor/pictures

var express = require('express');
var router = express.Router();


router.post('/', function (req, res, next) {
    console.log("got it");
   var path = "http://mytestplan.com/img/256/pdb.png";
var data = "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction(1,path,\"File uploaded\");</script>"
res.writeHeader(200, {"Content-Type": "text/html", });
html = "";
html += "<script type=\"text/javascript\">";
html += " var funcNum = 1;";
html += " var url = \"" + path + "\";";
html += " var message = \"Uploaded file successfully\";";
html += "";
html += " window.parent.CKEDITOR.tools.callFunction(funcNum, url, message);";
html += "</script>";
console.log(html);
res.write(html);
res.end();

});

module.exports = router;

app.js

var allowCrossDomain = function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
    res.header("Access-Control-Allow-Headers", "Authorization, Origin, X-Requested-With, Content-Type, Accept");
    next();
};
app.use(allowCrossDomain);

Sources Followed:

Screenshots in sequence of event:

On Uploading the image form local

On choosing the image upload tab in ckeditor and selecting the image from local

enter image description here

After clicking send to server get the response from server and no error till yet

enter image description here

On clicking the image info as given in ckeditor it should show image url in the text box,

enter image description here

When I again click the upload tab , the server response is in iframe with the script tag send from server and I then get the below error

Blocked a frame with origin "http://localhost:3001" from accessing a frame with origin "http://localhost:3010". Protocols, domains, and ports must match

Also its not allowing me to close the popup

Community
  • 1
  • 1
Mr AJ
  • 1,515
  • 3
  • 24
  • 40

1 Answers1

0

Many NodeJs developer has same issue. How to upload and browse images or files by CKEditor and Nodejs. As new ckeditor do not provide FREE file/image uploader like its predecessor Fckeditor.

So this solutiuon will help them to directly integrate Ckeditor very quickly with Nodejs along with file/image uploading option.

I have created simple solution with CkEditor and nodejs image uploader and browser for FREE. No free version available till now.

Github repository for this solution

Dhiraj
  • 96
  • 5
  • A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](http://meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted](http://stackoverflow.com/help/deleted-answers). – mrun Jul 11 '17 at 06:00
  • @Dhiraj the issue is of cross origin using the client and server that may be in hosted in diff server, it is also throwing the same error when I separate the client and server code – Mr AJ Aug 17 '17 at 09:24
  • I ran the backend for image upload for the same port as the client side, and then used micro service for the other functionalities form the backend API. Rest all worked smooth then, – Mr AJ Aug 12 '20 at 10:06