javascript - 使用javascript在两个aspx页面之间传递数据

标签 javascript c# asp.net sharepoint sharepoint-2010

我需要帮助在两个 aspx 页面之间传递数据(这些 aspx 页面存储在 SharePoint Designer 中)。我创建了一些 JavaScript,可以对我们网站上的指标进行一些简单的计算。

https://tandemhospitalpartners.sharepoint.com/SitePages/Home.aspx

以下 JavaScript 位于上面列出的 aspx 链接中。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <script type="text/javascript">
        window.onload = function () 
        {

        }
        
        function p1()
        {

            totalPts = 137;
            setTotalPts(totalPts);
            
            
            divId = document.getElementById('avg'); // element represents the ID 'countdown' for the div

            today = new Date(); //this represents todays date in the following format
            //Weekday ex. "Tue"
            //Month ex. "Aug"
            //Todays Date ex. "08"
            //Year ex. "2017"
            //Time ex. "13:44:54 GMT - 0500 (Central Daylight Time"


            svOpen = new Date(2017, 06, 17); // this represents the first day we accepted patients
            

            one_day = 1000 * 60 * 60 * 24; 
            //milliseconds
            //minutes
            //seconds
            //hours


            //We have been open for 23 days


            daysOpen = Math.ceil((today.getTime() - svOpen.getTime()) / (one_day));
            //subtracting SVNH open date from current date






            


            

            avgPts = parseFloat(totalPts)/parseFloat(daysOpen); 

            
            divId.innerHTML ="Average Patients Per Day: "+ avgPts.toFixed(1);
        }
         function GetDays(element) 
        {
            
            var el = document.getElementById(element);
            today = new Date();
            var cmas = new Date(today.getFullYear(), 6, 12);
            if (today.getMonth() == 6 && today.getDate() > 13) {
                cmas.setFullYear(cmas.getFullYear() + 1);
            }
            var one_day = 1000 * 60 * 60 * 24;
            el.innerHTML ="&nbsp;&nbsp;Days to open the second Hospital: &nbsp;&nbsp;&nbsp;"+Math.ceil((cmas.getTime() - today.getTime()) / (one_day));
        }
        function setTotalPts(totalPts)
        {
            totId = document.getElementById("leOne");

            totId.innerHTML = "This is my total patients: " + totalPts.toString();


        }

    </script>
</head>
<body onload="p1(); GetDays('count'); setTotalPts();"+"text"> <!-- this onload is passing the div ID to the function p1( element )
                                        element represents the ID -->

<div id='count' style="color: #e51400 ;
font-weight : 500;"></div>
</body>


<body>

<div id='avg' style="color: #e51400 ;
font-weight : 500;"></div>



</body>

<body>

<div id='leOne' style="color: #e51400 ;
font-weight : 500;"></div>




</body>
</html>


<!-- to keep a running count of the days i will have to subtract svOpen from todaysDate

我的目标是将totalPts 传递给位于不同aspx 文件上的HTML ID。

这是指向 aspx 文件的链接,其中包含我也想发送的 HTML ID。

https://tandemhospitalpartners.sharepoint.com/ININD/SitePages/Home.aspx

这就是我真正困惑的地方。我不知道如何实现这个结果。如果有人知道如何使用 JavaScript 来完成此操作,我将不胜感激!

最佳答案

您无法从另一个页面的客户端访问另一个页面的 html,因为网络是无状态环境。但是,从第一页开始,您可以通过查询字符串将数据传递到下一页,也可以将数据保存到 localStorage,然后导航到下一页并从 localStorage 检索数据。我更喜欢查询字符串,因为它看起来只是您想要传递的数字。

假设您有一个打开第二页的按钮

<asp:Button runat="server" ID="btnNext" OnClientClick="location.href='https://tandemhospitalpartners.sharepoint.com/ININD/SitePages/Home.aspx?totalPointes=' + getTotalPoints()" Text="Inind Home"></Button>

然后在目标页面中从查询字符串中获取总点数并将其保存到元素中。例如

$("#SomeID").val(getvaluefromQuerystring());

关于javascript - 使用javascript在两个aspx页面之间传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45700077/

相关文章:

javascript - 当我寻找十六进制值时,我得到二进制作为答案

javascript - 无法从 SvelteKit 中的 API 获取数据

c# - SlimDX Device.Reset 崩溃并出现 "D3DERR_INVALIDCALL: Invalid call (-2005530516)"错误

c# - 在 ASP.NET MVC 中与 Facebook/其他身份验证一起实现表单例份验证的正确方法是什么

c# - JavaScript 哈希和等效的 .NET 算法

javascript - 简单的javascript字符串提取

javascript - 如何从 URL 查询字符串中获取参数值

c# - C# 中的 "|="运算符是什么?

c# - .NET 中的 printf 格式

c# - 在 C# 中查找字形宽度(私有(private)字体)