如何用javascript引用https

时间:2014-01-22 05:03:56

标签: javascript http https

我需要我的页面才能将人们引导到网站的https部分,仅在此预订系统的第3步,我不希望整个网站在https上运行。

基本上我拥有一家汽车租赁公司,并且希望人们填写的信息部分位于https服务器上,我已经拥有证书并且我的网站正在运行

此代码位于我希望他们点击的页面上,然后将它们带到另一页,但使用https: 如何让这个javascript代码输出一个https链接,而不是现在输出的链接

<div class="button" style=""><a href="javascript:processFeesPage();"> <?php l_e("Click to continue"); ?></a></div>

基本上

      <script type="text/javascript">
        function processFeesPage()
        {
            var feeschart;
            feeschart = MM_findObj('feeschart');
            objtotaltotaltax = MM_findObj('totaltotaltax');
            // save with Ajax, cleaning a bit the code and go to step-4 (customer details)
            var http_request =  getRequestAjax();
            http_request.open('POST','<?php echo VIRTUAL_ROOT; ?>scripts/saveformajax.php', false);      
            var parameters = '';
            parameters = encodeParam('rentalitems',feeschart.innerHTML);
            parameters = parameters + "&" + encodeParam('totalcost',objtotaltotaltax.innerHTML);
            parameters = parameters + "&" + encodeParam('pricereturn','<?php echo $pricereturn; ?>');
            for (var i in selected_values)
                parameters = parameters + "&" + encodeParam(i,""+selected_values[i]);
            http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1;");
            http_request.setRequestHeader("Content-Encoding", "iso-8859-1");
            http_request.setRequestHeader("Content-Length", parameters.length);
            http_request.setRequestHeader("Connection", "close");
            http_request.send(parameters);
            document.location= './step-4';
        }
      </script>

1 个答案:

答案 0 :(得分:1)

这一行

document.location= './step-4';

使用当前上下文生成整个网址:http://rentacar.com/step4

由于您现在想要切换到新的protocol (https),因此无法使用当前使用的.快捷方式。

你可以放入完整的路径:

document.location= 'https://rentacar.com/step4'

或者您可以尝试以编程方式解决问题。例如:

var currentUrl = 'http://' + window.location.hostname + '/step4'