drol55885602 2018-05-01 04:11
浏览 231

使用Javascript访问$ _GET并更新<script data-email =“”> </ script>

This is a bit tough for me to do appreciate some help.

I give this code to clients to place on their site, pass data to me and load dynamic content:

<script type="text/javascript" src="https://example.com/countdown_timer_evergreen.php" 
data-launch_owner_email_hashed="94bd214b329301668349352de430bb6d" 
data-launch_id="43" data-email="<?php echo $_GET['email'];?>">
</script>

Since a lot of clients don't have php, I have to use Javascript to capture the email from $_GET. So I use such code:

<script>
    var getUrlParameter = function getUrlParameter(sParam) 
      {
        var sPageURL = decodeURIComponent(window.location.search.substring(1)),
        sURLVariables = sPageURL.split('&'),
        sParameterName,
        i;
        for (i = 0; i < sURLVariables.length; i++) 
          {
            sParameterName = sURLVariables[i].split('=');
            if (sParameterName[0] === sParam) 
              {
                return sParameterName[1] === undefined ? true : sParameterName[1];
              }
          }
      }
    var email = getUrlParameter('email');
  </script>

How can I update my original code, replace with the javascript output of the content (capture the email with JS above) and give them the code? I want to give them 1 piece of code. Not sure how to pass the value of email between scripts.

And this is my code that receives the data (countdown_timer_evergreen.php)

<?php 
//Allow cross-origin requests 
header('Access-control-allow-origin: *'); 

$action = isset($_GET['action'])?$_GET['action']:null; 
switch ($action){ 
    case 'load-template': 
        DoLoadTemplate(); 
        break; 
    default: 
        DoDefault(); 
} 
exit;  

function DoDefault(){ 
    header('Content-type: text/javascript'); 

?>
(function(window){ 
    var currentScript = document.currentScript; 
    var apiUrl = currentScript.src; 

    if (!('jQuery' in window)){ 
        loadJQuery(initialize); 
    } else { 
        initialize(); 
    } 

    function loadJQuery(cb){ 
        var script = document.createElement('script'); 
        script.src = 'https://code.jquery.com/jquery-3.3.1.min.js'; 
        script.type = 'text/javascript'; 
        script.addEventListener('load', cb); 
        document.getElementsByTagName('head')[0].appendChild(script); 
    } 

    function initialize(){ 
        var $currentScript = $(currentScript); 

        var params = $.param({ 
            action: 'load-template' 
            , launch_owner_email_hashed: $currentScript.data('launch_owner_email_hashed')
            , launch_id: $currentScript.data('launch_id') 
            , email: $currentScript.data('email') 
        }); 
        console.log(params);

        $.get(apiUrl, params).then(function(html){ 
            var div = $('<div>').html(html); 
            $currentScript.after(div); 
        }); 
    } 
}(this)); 
<?php 
} 

function DoLoadTemplate()
    { 
        header('Content-type: text/html; charset=utf-8'); 
        $launch_owner_email_hashed = htmlspecialchars($_GET['launch_owner_email_hashed']);
        $launch_id = htmlspecialchars($_GET['launch_id']);
        $email = htmlspecialchars($_GET['email']);
        
    
    if($_SERVER['SERVER_ADDR']=="::1")
        {
            $root = "http://local.moosh.com/eg-launch-timer";
        }
    else 
        {
            $root = "https://moosh.com/eg-launch-timer";
        }
    ?> dd
<iframe src="<?php echo $root.'/'.$launch_owner_email_hashed.'/'.$launch_id.'/'.$email;?>" style="width:100%; height:100%; border:none;">    
</iframe>

<?php } ?>

Open to ideas

Thanks

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器