none
How to get information from another web page of the same domain

    Question

  • Hello:

    I have an online trading account, I can login and check my account balance and buy/sell stocks.

    The account balance page’s URL is: https://www.mytrading.com/account_page; and the trading page’s URL is: https://www.mytrading.com/trade_page;

    On the account balance page, I have a Mutation Observer JavaScript to monitor my account balance. (function AccountBalanceJS().) It can show account balance as long as its value is changed.

    On the trading page, I have a Mutation Observer JavaScript to monitor the stocks prices (function PriceChangeJS().) It can show the prices as long as the current price is different from last shown price.

    Now I want to write another simple JavaScript function (function BuyStocks()) to buy stocks if its current price is 5%+ than its open price of the current trading session. However, the trading JavaScript needs to know my current account balance in order to decide how much money I can buy for one specific stock.

    I can create a UWP project with 2 WebViews, one for account balance page at: https://www.mytrading.com/account_page; (webView1) to run the Mutation Observer JavaScript to monitor account balance changes.

    Another for trading page at: https://www.mytrading.com/trade_page; (webView2)  I can run Mutation Observer JavaScript to monitor the stock prices changes and trading JavaScript, but this trading function needs the account balance information.

    And I can use window.external.notify to pass the account balance to C#.

    But how I can pass the account balance information to my trading JavaScript function? (From AccountBalanceJS() in webView1 to BuyStocks() in webView2?)

    Please advice.

    Thanks,

    Tuesday, March 12, 2019 2:28 AM

Answers

  • Hi,

    Based on your words, you say that you could get the balance from AccountBalanceJS() in webview1, right? In the end AccountBalanceJS(), call windows.external.notify to send the value to your UWP project. 

     private void ScriptNotify(object sender, NotifyEventArgs e)
            {
                var balance = e.Value;
            }

    Then you could pass the balance value as a parameter to the JS code- BuyStocks() in webView2. Like this link:Interacting with WebView content.


    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by zydjohn Thursday, March 14, 2019 10:45 PM
    Thursday, March 14, 2019 6:03 AM
    Moderator

All replies

  • Hi,

    I have to say that according to the network policy, we could not open your links. But for your question, why not pass the account balance information as a parameter to your trading JavaScript function as you could get this in the account balance page? For example, use windows.external.notify to get the account balance and save it in the project's memory from the account page. Then pass it as parameter to the BuyStocks(balance) function in another page.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 13, 2019 3:29 AM
    Moderator
  • Hello:

    Thanks for your reply, but I don't quite understand your meaning.  Is it possible that you show me some code for what you want to do.  As I can't figure out the technical details.

    Thanks,

    Wednesday, March 13, 2019 5:46 PM
  • Hi,

    Based on your words, you say that you could get the balance from AccountBalanceJS() in webview1, right? In the end AccountBalanceJS(), call windows.external.notify to send the value to your UWP project. 

     private void ScriptNotify(object sender, NotifyEventArgs e)
            {
                var balance = e.Value;
            }

    Then you could pass the balance value as a parameter to the JS code- BuyStocks() in webView2. Like this link:Interacting with WebView content.


    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by zydjohn Thursday, March 14, 2019 10:45 PM
    Thursday, March 14, 2019 6:03 AM
    Moderator