Concentrate on implementing Cross-domain Ajax functionality in Opera browser

For a unique and interesting browsing experience, try using Opera 9.62 to explore the nuances of cross-sub-domain JavaScript calls with Ajax. To understand this better, follow these instructions by placing three simple files on appropriate domains.

foo.html (parent of boo.html iframe) at foo.example.com

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>foo</title>
<script type='text/javascript'>

    document.domain = 'example.com';

    function sendRequest() {
        window.frames['boo'].sendRequest();
    }

</script> 
<head>
<body>

    <input type="submit" value="sendRequest" onclick="sendRequest();" />

    <iframe name="boo" src="http://boo.example.com/boo.html"></iframe>

</body>
</html>

boo.html (iframe of foo.html) at boo.example.com

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>boo</title>
<script type='text/javascript'>

    document.domain = 'example.com';

    function sendRequest() {
        var request = null;

        if (window.XMLHttpRequest) { 
            request = new XMLHttpRequest(); 
        } else { 
            request = new ActiveXObject('Microsoft.XMLHTTP'); 
        }

        if (request) {
            request.open('GET', 'http://boo.example.com/helloworld.php', true); 

            request.onreadystatechange = function() {      
                if (request.readyState == 4) {
                    var result = request.responseText;

                    alert(result);
                }
            }

            request.send('');
        }
    }

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

helloworld.php at boo.example.com

<?php
    echo 'Hello World!';
?>

If you run the above code in browsers other than Opera 9.62, it will function perfectly (tested in Safari, Firefox, Chrome). However, in Opera, a security violation error occurs. Can anyone shed light on this issue? I have a solution that I will share later (I welcome your input too), but I am also eager to hear different perspectives on this problem.

UPDATE: After testing on the latest Opera 10.63, it appears that this issue no longer persists. Therefore, you must specifically use Opera v9.62 to encounter this challenge.

Answer №1

Seems like this version of Opera might not be compatible with document.domain.

Past versions of Opera didn't support it, so it's likely that 9.62 won't either.

Maybe try setting the domain to boo.example.com and see if that helps, just in case it surprisingly does work with 9.62.

Based on information from , it seems like XMLHttpRequest is supported fine and should work as expected with var request = new XMLHttpRequest().

Answer №2

My initial recommendation was to enable CORS, however it appears that feature has not been implemented yet. To learn more about this issue, you can visit the following link:

Answer №3

Here is the code snippet that successfully runs on Opera 9.62...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>boo</title>
<script type='text/javascript'>

    document.domain = 'example.com';

    function sendRequest() { 
        setTimeout(function() {
            var request = null;

            if (window.XMLHttpRequest) { 
                request = new XMLHttpRequest(); 
            } else { 
                request = new ActiveXObject('Microsoft.XMLHTTP'); 
            }

            if (request) {
               request.open('GET', 'http://boo.example.com/helloworld.php', true); 

               request.onreadystatechange = function() {                  
                    if (request.readyState == 4) {
                       var result = request.responseText;

                       alert(result);
                    }
                }

                request.send('');
            }
        }, 1);
    }

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

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

Yii's ajaxForm validation feature unfortunately only checks a portion of the form for errors

I have a Yii form that collects data for three models and utilizes ajax validation on change and submit: <?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'offer-form', 'enableAjaxValidation&apo ...

What is the best approach for managing Promise rejections in Jest test scenarios?

Currently, I am engaged in a node JS project where my task is to write test cases. Below is the code snippet that I am working on - jest.mock('../../utils/db2.js') const request = require('supertest') const executeDb2Query = require(&ap ...

The npm lint command is throwing an "Observable `source is deprecated`" error

When I execute the command npm lint on my code, I receive a warning stating "source is deprecated: This is an internal implementation detail, do not use." The specific part of the code causing this issue is shown below: set stream(source: Observable<a ...

Sending an array to another file upon button click event in a React application

Hey everyone, I'm currently getting started with React. I have this interesting situation where I need to handle an array of IDs that are obtained from selected checkboxes. My goal is to pass this array to another file called Employee.js when a button ...

What strategies can be utilized to enhance the cleanliness of these functions?

Is there a way to avoid adding new lines of JS code every time I add a new image to the HTML? $(document).ready(function() { $('.btn').click(function() { var bid = $(this).attr('id'); if(bid=="img1" || bid == "img2" || bid == "img3"){ ...

The Bootstrap modal will not appear when the parent container's position is fixed

I am having an issue with a bootstrap modal that I am using as an instruction guide. My goal is to keep it fixed at the top-right corner of the viewport, so I tried using the fixed position. However, when I do this, the modal turns grey. On the other han ...

Transforming form inputs into JSON structure

<form name = 'test' > <input type='text' name = 'login'> <input type='email' name = 'email'> </form> When I try to convert the form data using JSON.serialize($(form)).serial ...

Ways to resolve the issue of the 'setConfirmDelete' property not being found on type 'JSX.IntrinsicElements' in React.js

index.tsx const setConfirmDelete = (state, close) => { return ( <Modal show={state} onHide={close}> <Modal.Header> <Modal.Title>Title</Modal.Title> </Modal.Header> <Modal.Body> 'T ...

AJAX request lacks the 'access-control-allow-origin' header

I'm currently integrating a weather API into my app to display real-time weather information. Although I've used this API before, I am now attempting to fetch the data asynchronously using AJAX to avoid full page reloads. Below is the JavaScrip ...

Enhance the appearance of the jQuery document.ready function

I'm attempting to customize the jQuery document.ready function <html> <head> <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <script type="text/javascript> $(function() { c ...

Try utilizing a variety of background hues for uib progressbars

Looking to incorporate the ui-bootstrap progressbar into my template in two different colors, background included. My initial idea was to stack two progress bars on top of each other, but it ended up looking too obvious and messy, especially in the corner ...

Having trouble getting gulp set up and running with npm?

I am currently in the process of setting up gulp using npm in order to execute my project. Based on my understanding, all I need to do is enter "npm install gulp" in the command line at the location of my project like this : https://i.stack.imgur.com/hPU ...

I am encountering an issue where my Vue navbar is successfully changing the route but not updating the corresponding router-view

I have been working on a single-page application using Vue and I encountered an issue with the navbar when navigating through routes. The problem is that after the first click on a navbar item, the route changes successfully but the router-view does not up ...

What is the best way to input a dynamic post array in PHP?

Explaining this might be challenging, but I will do my best. I have multiple input posts with custom conditions, which means there can be as many custom conditions as needed. Here is the HTML: <input name="type[]" value="type 1"> <input nam ...

What is the best way to send an email with a randomly generated HTML output using a <button>?

I am currently working on a feature where a random HTML output is sent to me via email whenever a user clicks on a button on the website page. The user receives a code when they click the button, and I want that code to be emailed to my address automatical ...

Using v-model with the Toast-UI editor in Vue.js adds a dynamic and

Is there a way to bind the input value while using toast-ui vue-editor since it doesn't support v-model? Here is my setup for toast-ui: import '@toast-ui/editor/dist/toastui-editor.css'; import { Editor } from '@toast-ui/vue-editor&apos ...

Submitting forms using Ajax within a modal pop-up box

Here's an interesting issue that I'm facing: On a test page, when the user clicks to view results, a modal box opens with 3 select boxes. Select Box 1 populates Select Box 2, which then populates Select Box 3 The Problem: After clicking submi ...

The largest allowable call stack size within jQuery version 1.9.0

I have a question about poorly written code that I've been experimenting with. It's messy, but it's just for fun. I was attempting to create a "like system" where a user clicks on a button and the object ID associated with the button is sent ...

Executing an external HTTP request within an ExpressJS middleware prior to rendering the response

Currently, I am facing a challenge while trying to utilize Express middleware for a login request. The default route generates an external URL that redirects to /login?code={login-code}. This URL triggers an external HTTP request to obtain the user_id and ...

Troubles with loading images on Node.js, Express, and EJS powered Bootstrap 5 navbar

Currently, I am in the process of creating a website using express/node.js/ejs. However, I am facing challenges when it comes to constructing a navbar with Bootstrap 5.0. In my app.js file, I have included express.static: app.use(express.static('publi ...