I am trying to execute the below code to open URL using javascript
var Urlone = document.getElementById('00N0b00'),
opening = window.open(Urlone),
opening.onload = function() {
var Urltwo = opening.document.getElementById('00GG')
window.open(Urltwo);}
This works and opens Urltwo when Urlone is from same domain as Origin URL, but Urltwo does not open when Urlone is from different domain than Origin.
I know its because or CORS standards, but I need help to get around this.
I already tried downloading chrome extensions which relaxes CORS but it did not work. I don’t want to use jquery or anyorigin.com. Looking for a possible solution using javascript.
CORS (Cross-Origin Resource Sharing) is a system, consisting of transmitting HTTP headers, that determines whether browsers block frontend JavaScript code from accessing responses for cross-origin requests. (https://developer.mozilla.org/en-US/docs/Glossary/CORS)
You cannot inject JavaScript into a window when cross-origin resource sharing is disabled and this is by design.
Possible workarounds:
If you have access to the server serving Urltwo, changing CORS settings is the best solution.
If you do not have access to the server, but you can edit the document served at Urltwo, you can communicate between the documents via document.postMessage (https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) or by encoding information in the URL (query string or hash).
If you have access to neither, you can use a proxy that fetches the contents at Urltwo, sents the correct CORS headers and sends the result back to you.