【问题标题】:Add parameter to iframe source将参数添加到 iframe 源
【发布时间】:2017-10-06 22:16:03
【问题描述】:

我需要在我的 Android 应用程序 WebView 中显示一个 iframe,该 iframe 存在于一个位于 Web 服务器上的 HTML 文件中。 在根据用户输入在 WebView 中显示它之前,我需要向 iframe 源添加一个参数。

我的php代码:

    <?php

    if (isset($_POST['amount'])){
        $amount = $_POST['amount'];
        $intamount = (int)$amount;
        echo $intamount;
    }

    if (isset($_POST['currency'])){

        $currency = $_POST['currency'];
        $intcurrency = (int)$currency;
    }

    if (isset($_POST['lan'])){

        $lan = $_POST["lan"];
    }

    if (isset($_POST['email'])){

        $email_address = $_POST["email"];
    }

    if (isset($_POST['name'])){

        $name = $_POST['name'];
    }




    $iframe_source = 'https://sampleurl.php?sum='.$intamount.'&currency='.$intcurrency.'&cred_type=1&trButtonColor=008080&email='.$email_address.'&contact='.$name;

    echo $iframe_source;

?>

<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8"/>



    </head>

    <body>


        <iframe width="370" height="455" src="<?php
            echo $iframe_source;
        ?>" frameborder="5" allowfullscreen></iframe>

    </body>

</html>

例如,我可以向 php 文件发出 post 请求吗?如果是,有没有办法在 php 文件中添加 html 代码并将其显示在我的 WebView 中? 有一个更好的方法吗? 非常感谢。

【问题讨论】:

  • 这不是一个真实的来源,它只是一个例子,我需要能够根据用户输入从我的 Android 应用程序中调整它
  • 当然,sampleurl 只是一个例子,真实的是你提供的格式,它工作正常,我猜是在接收参数之前显示 iframe,它可能是我收到该错误的原因

标签: php android html iframe android-webview


【解决方案1】:

收到用户输入后,为什么不从 Web 服务器加载 PHP。

您可以执行 POST 或 GET 请求。

所以加载状态http://example.com/webview.htmlhttp://example.com/webview.php?user_paramter=value

现在webview.php 看起来与webview.html 基本相同,只是有一些小的变化:

<?php
    $user_paramter = $_GET['user_paramter'];
    $link = 'https:iframedemo.php?sum=13&currency=1&user_paramter=' . $user_paramter;
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"/>
    </head>
    <body>
        <iframe width="370" height="455" src="<?php
            echo $link;
        ?>" frameborder="0" allowfullscreen></iframe>
    </body>
</html>

您的应用将收到一个具有正确 iframe 源/链接的 HTML 文件

如果在用户输入之前接收到 PHP 脚本,则$_POST$_GET 为空,并且不会起作用。因此,如果您在 PHP 脚本的开头执行 var_dump($_POST) 并且您有类似 array(0) {} 的内容,那么问题不在于 PHP 脚本或 iframe 本身。您必须找到一种在用户输入后如何调用页面的方法。

【讨论】:

  • 也许你可以删除问题和答案上的所有命令,这样漏洞看起来就不会那么乱了
猜你喜欢
  • 2019-05-13
  • 2023-03-21
  • 1970-01-01
  • 2013-01-13
  • 2012-11-23
  • 2017-09-17
  • 2019-07-20
  • 2014-03-01
  • 1970-01-01
相关资源
最近更新 更多