Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Persisting data between two separate tabs
Message
 
 
To
All
General information
Forum:
Javascript
Category:
Coding, syntax & commands
Title:
Persisting data between two separate tabs
Miscellaneous
Thread ID:
01662264
Message ID:
01662264
Views:
35
UPDATE. Got it to work:
VendorsService.prototype.setPurchaseOrder = function (order) {

        if (!_.isEmpty(order)) {
            localStorage.setItem("purchaseOrder", JSON.stringify(order));
        }
        else {
            localStorage.removeItem("purchaseOrder");
        }
    };

    VendorsService.prototype.getPurchaseOrder = function () {
        return JSON.parse(localStorage.getItem("purchaseOrder"));
    };
Hi everybody,

I'm looking at this page

https://www.w3schools.com/jsref/prop_win_sessionstorage.asp

I want to save some complex object and pass it from one page to another which I open in a new window (it actually opens in a new tab in my Google Chrome browser). Once I got the data I want to reset it back to {}.

My current service code is the following:
VendorsService.prototype.setPurchaseOrder = function (order) {
        purchaseOrder = order;
    };

    VendorsService.prototype.getPurchaseOrder = function () {
        return purchaseOrder;
    };
and the code that sends to my receiver page is the following:
purchaseOrdersCrudController.prototype.receiveOrder = function () {
        services.Vendor.setPurchaseOrder(this.model);
        const linkUrl = "RetailInventory/Receivers#/new/" + this.model.internlPo;
        window.open(linkUrl, "_blank");
    };
So, do you think I should attempt to change the service code to use localStorage instead and in the receivers code use something like
const order = SW.serviceLoader.Vendor.getPurchaseOrder();

            this.logInfo("Attempting to retrieve PO from Vendor service");

            if (!_.isEmpty(order) && order.hasOwnProperty("internlPo")) {
                this.logInfo("Successfully retrieved PO from the Vendor service");
                this.purchaseOrder = order;
                this.model['internlPo'] = order.internlPo;
            }
            else {
                if (SW.serviceLoader.StateParams.internalPo) {
                    this.model['internlPo'] = SW.serviceLoader.StateParams.internalPo;
                    this.doPurchaseOrderLookup();
                }
            }
and set the service order to {} right after I retrieved it in the first if statement?

Anybody used that localStorage and can show me example?

Thanks again.
If it's not broken, fix it until it is.


My Blog
Reply
Map
View

Click here to load this message in the networking platform