What is the process for creating a widget that can be seamlessly integrated into someone’s website and hosted on your own site

In relation to this previous question.
After researching JSONP and conducting some tests, I've realized that I am completely clueless about what I'm doing...

What is required?

I am developing a customer service tool for people to integrate into their websites. Ultimately, anyone who wants our web application embedded on their site will need to obtain JavaScript code along with an authorization key.

What do I currently have?

I have tinkered with the code a bit and this is where I stand:

homepage.php (client side)


<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
(function($) {
var key= "12345";
var url = 'http://www.example.com/json.php?callback=?&auth=' + key + '';

$.ajax({
    type: 'GET',
    url: url,
    async: false,
    jsonpCallback: 'jsonCallback',
    contentType: "application/json",
    dataType: 'jsonp',
    success: function(json) {
       document.write(json.csBlock[0].frame); //Call to the iFrame
       // document.write(json.csBlock[0].layout);
       // document.write(json.csBlock[0].core);
    },
    error: function(e) {
       console.log(e.message);
    }
});

})(jQuery);
</script>
</head>
<body>

 </body>
 </html>

This JavaScript triggers a callback to my server...

json.php (server side)


<?php 
if ($_GET['auth'] === "12345"){
?>
jsonCallback(
    {
        "csBlock":
        [
            {
                "frame": "<iframe src='http://www.example.com/content/testpage.php'></iframe>",
                "layout": "<link rel='stylesheet' href='http://www.example.com/css/klantpage.css'>",
                "handle": "<script src='http://www.example.com/js/self/widgetScript.js'></script>",
                "core": "<div class='dashboard_widget'></div><div id='chatContainer' class='chatContainer'><div id='view_ajax' class='view_ajax'></div></div><div id='ajaxForm' class = 'ajaxForm'><textarea id='chatInput'></textarea></div><input type='button' value='Send' id='btnSend' class = 'btn btn-primary'></div></div>"

            }
        ]
    }
);
<?php
}
else {
    ?>
    jsonCallback(
    {
        "csBlock":
        [
            {
                "layout": "<div style='width: 250px; height: 50px; background-color: #842979; position: fixed; bottom: 0; right: 5%; border-top-left-radius: 5px; border-top-right-radius: 5px; text-align: center; line-height: 300%; color: white; font-family: calibri; font-size: 13pt;'>KEY NOT PERMITTED</div>"
            }
        ]
    }
);




    <?php
}
?>

The key provided by users should be "12345"
Considering the iframe method may not be ideal, I have decided to explore other options.
As shown in the json.php file, I tried building something using div elements. However, when I include "handle" along with the divs, it results in a 500 internal server error.
I suspect this error is due to widgetScript.js attempting to call a PHP file from another server...
With iframes out of the equation and HTML element based construction also posing challenges, I find myself at a loss for solutions.

Question

How can I create a chat widget professionally and securely utilizing JSONP?
My primary concern is preventing unauthorized manipulation of the JavaScript to access the chat widget.


This inquiry may require more extensive assistance beyond StackOverflow.
Feel free to direct me to external resources if necessary.

Any advice, guides, or tutorials would be highly appreciated!

Answer №1

Is there a way to create a chat widget using JSONP that is both professional and secure? I'm worried about potential JavaScript alterations by users.

One alternative could be utilizing WebSockets, which are faster and more secure.

I speak from experience in developing Professional Chat Widgets for various web applications, both internal and external, using both JSONP and WebSockets.

A WebSocket-based widget would reduce the workload on the host website, require less client-side JavaScript, and offer easier code maintenance.

This approach also allows for domain-specific access controls.

These are just my thoughts on the matter, but I'm open to further discussion if you're interested.

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

Ways to effectively utilize the results from php functions triggered by ajax in our document

I have a mobile application that constantly updates latitude and longitude values to my PostgreSQL database. I am attempting to display these updated points on an OpenLayers map using jQuery and AJAX. However, I am encountering a problem: after clicking th ...

Failed to cast value "undefined" to ObjectId in the "_id" path for the model "User"

I've been encountering an issue that I can't seem to resolve despite searching on Stack and Google. My ProfileScreen.js is meant to display a user's profile, but when attempting to view the profile, I receive this error: "Cast to ObjectId fa ...

Every time I use Get for ajax calls, I keep getting hit with a frustrating

Initially, I was making a call to a [web method] using the POST method. However, since I need to receive data back, I attempted to switch to using the GET method instead. The previous implementation using POST was successful. Unfortunately, using GET resu ...

Create a roster of individuals who responded to a particular message

Can a roster be created of individuals who responded to a specific message in Discord? Message ID : '315274607072378891' Channel : '846414975156092979' Reaction : ✅ The following code will run: bot.on("ready", async () = ...

Dynamically saving JSON data into a database using PHP

I receive the following JSON data: {"1":["77","77"],"2":["33","55","66"]} In PHP, I decode it as follows: $organize = json_decode($json); To store these values in a database, I iterate over them like this: foreach($organize->{1} as $pos => $div){ ...

Error: Unable to access the 'version' property of null

Having trouble installing any software on my computer, I've attempted various solutions suggested here but none have been successful. $ npm install axios npm ERR! Cannot read property '**version**' of null npm ERR! A complete log of this ru ...

Differences Between 'this' and 'self' in Classes

I am currently working with ES6 Classes and I'm struggling to grasp why I am able to access the this variable within one of the methods. //CODE class Form{ constructor(){ var self = this; } assemble(){ log(self); ...

Step-by-step guide for launching a Next.js/Node application

Currently, I am developing a full-stack project utilizing a next.js application for the front-end and a node/express server for the API. The front-end and back-end are running on separate ports. Here is how my application is configured: https://i.stack.im ...

Discovering ways to showcase JSON response in JavaScript or PHP

Currently, I am integrating the Coin Warz API into my website. The API sends responses in JSON format. I have attempted to display this data in a table format using PHP, but unfortunately, I am encountering difficulties. The JSON Response is as follows: [ ...

The Google Javascript API Photo getURL function provides a temporary URL that may not always lead to the correct photo_reference

Currently, I am integrating Google Autocomplete with Maps Javascript API into my Angular 5 application. As part of my website functionality, I fetch details about a place, including available photos. The photo URL is obtained through the getURL() method. ...

angularjs currency conversion tool

Is it possible to choose only 3-4 currency values from a drop-down list, where the selected value will determine the base URL for fetching JSON data? For instance, if I select USD as the first value, the JSON data should be retrieved from . ...

Popup mode is utilized by CodeIgniter error pages to display error messages

Is there a way to show error messages without being redirected to the error pages located in application\errors\*error_pages*? We want to remain on the same page and display any errors that occur in a popup. Can someone provide an example code fo ...

"Extending Material-UI: Utilizing Multiple Snackbar Components

I've been struggling to display multiple warnings using Snackbar from the Material UI library in my React project. I haven't found any examples with React, only Vue. Can anyone help me with this? Here is the code that I have tried so far: https: ...

Relocating sprite graphic to designated location

I am currently immersed in creating a captivating fish animation. My fish sprite is dynamically moving around the canvas, adding a sense of life to the scene. However, my next goal is to introduce food items for the fishes to feast on within the canvas. Un ...

What could be the reason behind the disruption in this JavaScript associative array?

I'm facing an issue with my associative array, which I have confirmed through console.log to be initially: this.RegionsChecked = {"US":true,"APAC":true,"Canada":true,"France":true,"Germany":true,"India":true,"Japan":true,"LATAM":true,"MEA":true,"UK": ...

Error in Passport JS: Trying to use an undefined function

I've been struggling with debugging my code in Express and Passport. I've tried following solutions from others but can't seem to get it right. Any help or useful links would be greatly appreciated. Here is the error message along with the ...

Using VBA and Selenium to access iframes within HTML with the #document tag

I am currently facing a challenge in accessing the HTML content within two iframes using Selenium Basic in VBA. Due to restrictions on our machines, we are unable to use IE and other tools like Python are not available to us. In the past, I was able to ac ...

Guide to Utilizing the Import Function in a Vue 3 Template

Working on a Vue 3 project, my setup includes a stuff.ts file with helpful functions that I need to utilize in my template. <script lang="ts"> import { defineComponent, onMounted } from 'vue' import { doSomething } from ' ...

The speed at which Laravel loads local CSS and JS resources is notably sluggish

Experiencing slow loading times for local resources in my Laravel project has been a major issue. The files are unusually small and the cdn is much faster in comparison. Is there a way to resolve this problem? https://i.stack.imgur.com/y5gWF.jpg ...

I can't seem to figure out what's wrong with my code because it keeps saying "No database selected" even though I have tried multiple ways to fix it

Hello everyone, I am new to PHP and encountering an error that is preventing me from connecting to the database. Would anyone be able to take a look at my code and see if there are any mistakes? <?php $dbconnection = "localhost"; $dbusername = "root"; ...