Utilizing a shared variable between JavaScript and VB .NET within a web browser control

I have a VB.Net form application with a webbrowser control. I've implemented an HTML5 page as a string and loaded it in the webbrowser using documenttext, which is functioning smoothly. However, when the user interacts with the page (containing a D3 chart) by dragging an item, I need to update a JavaScript variable and store it for retrieval by VB .Net the next time the page is reloaded.

Unfortunately, neither cookies nor localstorage are effective solutions in this scenario because the page is hosted on a local filesystem rather than a server. Attempting to use these methods results in a null or undefined reference error in the JavaScript.

I am not interested in transferring the variable to a remote MySQL server for storage due to the slowdown it introduces. Ideally, I'm looking for a local solution that can be executed without network dependencies.

Answer №1

After conducting thorough research, I have discovered the solution. By setting the ObjectForScripting property of the webbrowser control, you can enable the interaction between a windows form class and JavaScript on an HTML page. It is important to adjust the permissions of the class in order to expose it to COM. Subsequently, JavaScript can access any function or object within the class by utilizing the window.external object.

For further details, please refer to this page.

To delve deeper into this topic, visit this informative article.

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

Can you explain the term used to describe when specific sections of the source code are run during the build process to improve optimization?

One interesting feature I've noticed in next.js is its automatic code optimization during the build process. This means that instead of running the code every time the app is executed, it's evaluated and executed only once during the build. For ...

What are some ways to reduce the delay of Dark mode on a website?

Can anyone help me optimize the speed at which dark mode is applied on my website? Currently, there seems to be a delay between page load and the dark mode taking effect. Below is the jQuery.js code I am using: onload = function () { if (localStorage. ...

Updating the styling of the highlighted menu options throughout different sections

Currently using ASP.NET MVC "Razor" for my website project, picking up skills along the way. My site consists of 5 or 6 pages internally, with one page linking to an external site. My goal is to create a seamless user experience where all pages feel cohes ...

Struggling to store the results of multiple fetch API calls in an array for future access beyond the function

fetching data from multiple APIs and storing it in an array has been a challenge. While attempting to set the data using useState, only one piece of data successfully makes it into the array. Even after trying Promise.all method, the same issue persists al ...

Merge arrays in map function based on label and aggregate information

In my possession is an array filled with data from various streaming channels, categorized by shift (Morning and Afternoon). I dedicated the night to experimenting with different functions like reduce, but unfortunately, I hit a wall and couldn't gra ...

Creating SQL statements using Visual Basic .NET

My current task involves inputting data into a text box on an ASP.net 3.5 page. Once I click the submit button, I want this information to be saved in a SQL Server database. Could someone provide guidance on how to achieve this without exposing any detail ...

Adjust the width of the Bootstrap 5 progress bar in Vue based on the progression of a countdown timer

I am looking to utilize a bootstrap 5 progress bar in order to display the remaining time of a countdown. I have set up the necessary markup within my vuejs component template. <div class="progress"> <div class="progress-bar&quo ...

Passing data into Angular 4 components: a step-by-step guide

I'm facing a dilemma, I'm attempting to transfer data from one component to another in Angular 4, the data seems to be transferred successfully but it does not display, let me show you an example of the code: board.component.ts: import { Compon ...

Tips for incorporating a spinner during content loading within AngularJS

When the user clicks on the "Search" button, content will load and the button label will change to "Searching" with a spinner shown while the content is loading. Once the content has loaded (Promise resolved), the button label will revert back to "Search" ...

Angular JS is encountering an issue where the promise object is failing to render correctly

I'm currently learning Angular and I have a question about fetching custom errors from a promise object in Angular JS. I can't seem to display the custom error message on my HTML page. What am I missing? Below is my HTML file - <!DOCTYPE htm ...

React Native: Issue with Higher Order Component when utilizing the `onLayout` prop

The functionality of this component involves rendering the Placeholder. Once it acquires its layout, this higher-order component (HOC) updates the state and invokes the child component with the values. Everything seems to be working fine up to this point. ...

Error in Node.js child_process: unable to access the property '_writableState' as it is undefined

I'm currently working on integrating ffmpeg's functionality into a Node.js API by utilizing the child_process library. However, I encounter an error when trying to pass data to ffmpeg's stdin pipe, specifically getting a TypeError: Cannot re ...

Ways to downsize the ASPX page

I am currently working on a C#/ASP.NET web application in VS 2008 and facing an issue with the layout of my page. The buttons are appearing at the top, leaving a large gap between them and the resultLabel text. I have tried adjusting the label position m ...

Seeking assistance with sending variables to a dialog in Angular 2

Currently facing an issue where I need to pass the URL id from the previous page visited by a user to a service that can be referenced in a dialog. issuer.service.ts import { Injectable, EventEmitter } from '@angular/core'; import { Observabl ...

Update the nodes in a directed graph with fresh data

For the past few days, I've been facing a persistent issue that I just can't seem to find a solution for when it comes to updating nodes properly. Using three.js to render the graph adds an extra layer of complexity, as the information available ...

Transferring data between nested IFrames and triggering a page refresh

Looking for a way to pass multiple values between two embedded IFRAMES and refresh the receiving iframe src. Is there any solution you recommend, specifically in c# code behind file (asp.net)? Welcome any ideas and suggestions. Thank you. ...

Show the form when the button is clicked

I want to create an application that allows users to click on a button in the top right corner (check image) to hide one div (topics) and show another div (a form for adding a new topic). Here is what it looks like: https://i.stack.imgur.com/YeRTw.png ...

Changes in tabs are discarded when switching between them within Material UI Tabs

I have been experiencing an issue with the Material UI tab component where changes made in tabs are discarded when switching between them. It seems that after switching, the tabs are rendered again from scratch. For example, let's say I have a textFie ...

Verifying Objects with AngularJS JSON

Currently, I am using Angular to import a json file and showcase it in a table. Since some of the objects are different, I want to check if job.text is present. [ { "job": { "href": "www.google.com", "text": "Google" }, "api": " ...

Is there a way to add a background image similar to that?

Take a peek at the following site: . Notice how, as you scroll down, the background image appears to be fixed. It's almost like one of the pages acts as a window allowing you to see the background image. How can I achieve this cool effect? ...