HTML 表单自动填充 JavaScript 变量?

发布于 2024-12-28 00:31:42 字数 1763 浏览 1 评论 0原文

我正在为我的网站开发一个网络跟踪器,我传输数据的方式之一是在页面加载时自动填充表单数据,并使用 JavaScript 查询来填充每个字段......

我只需要以下字符串要从表单传输到另一个 php 脚本的文本.....

这方面很容易.....

表单(以及页面加载时收集的数据)隐藏在不可见的 iframe 中,以便它可以完成其任务在后台工作....

我需要主页(而不是 iframe)的 url自动插入到表单字段之一......

这是我到目前为止所拥有的,,,,

这是父页面上显示的代码(在本例中为“事件”):

    <iframe src="/track/track.html?events" height="500" width="500" scrolling="no" border="0"></iframe>

我知道我说的是不可见的 iframe, 500x500 大小是这样我可以在开发时看到幕后......

然后在 iframe 中我的代码是:

    <?php 
    $ip = $_SERVER['REMOTE_ADDR']; 

    $my_t = getdate(date("U"));

    $url = $_SERVER['REQUEST_URI'];

    ?>


    <html>

    <body> 

    <form action="/track/location.php" method="post">

    <input type="text" name="time" value="<?php echo "$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year] - $my_t[hours]:$my_t[minutes]:$my_t[seconds]" ?>">

    <input type="text" name="ip" value="<?php echo $ip ?>">



    // script A //

    <script type="text/javascript">

    document.write(window.location.search);

    </script>

    // end script A //


    // script B //

    <script>

    var url = ['alert(window.location.search)'];
    document.write("<input type=\"text\" name=\"url\" value=\"" + url + "\">");

    </script>

    // end script B //



    <input type="submit" name="submit" value="submit">

    </form>

脚本 A 将生成文本“?events”的语句,其中插入为“document.write”

脚本 B 将生成带有文本的文本框“alert(window.location.search)”预先插入为一个值......这就是我想要的......

我基本上需要能够组合脚本 a 和 b,以便它会写入 ( window.location.search)文本框中的数据(“?events”)而不是纯文本java命令....

如果有人可以帮助我,我将非常感激,提前感谢大家:)

i am developing a web tracker for my site, and one of the ways i am transferring data, is by auto-filling form data on page load, with javascript queries being used to fill each field.....

i just need strings of text to be transferred from the form to another php script.....

this side of it is easy.....

the form ( and data collected on page load ) is hidden in an invisible iframe, so that it can do its work in the background....

i need the url of the main page (not the iframe) to be auto inserted into one of the form fields.....

heres what i have so far,,,,

this is the code that is displayed on parent page (in this example "events"):

    <iframe src="/track/track.html?events" height="500" width="500" scrolling="no" border="0"></iframe>

i know i said invisible iframe, the 500x500 size is so i can see behind the scenes while developing....

then in the iframe the code i have is :

    <?php 
    $ip = $_SERVER['REMOTE_ADDR']; 

    $my_t = getdate(date("U"));

    $url = $_SERVER['REQUEST_URI'];

    ?>


    <html>

    <body> 

    <form action="/track/location.php" method="post">

    <input type="text" name="time" value="<?php echo "$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year] - $my_t[hours]:$my_t[minutes]:$my_t[seconds]" ?>">

    <input type="text" name="ip" value="<?php echo $ip ?>">



    // script A //

    <script type="text/javascript">

    document.write(window.location.search);

    </script>

    // end script A //


    // script B //

    <script>

    var url = ['alert(window.location.search)'];
    document.write("<input type=\"text\" name=\"url\" value=\"" + url + "\">");

    </script>

    // end script B //



    <input type="submit" name="submit" value="submit">

    </form>

script A will produce a statement of text "?events" where inserted as "document.write"

script B will produce a text box with the text "alert(window.location.search)" pre inserted as a value.... which is kind of what i want.....

i basically need to be able to combine script a and b so that it will write the (window.location.search) data ("?events") in the text box instead of the plain text java command....

i will be very greatful if anyone can help me, thanks in advance guys :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终陌 2025-01-04 00:31:42

这是你想要的吗?

var url = ['alert(' + window.location.search + ')'];

Is this what you want?

var url = ['alert(' + window.location.search + ')'];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文