duandan4680 2013-12-01 10:26
浏览 29

我可以从两个页面向同一个JavaScript发送变量吗?

I have 2 pages where the user gives data that needs to be stored (the 1st is a string from the first page and the rest comes from a form from the second page). This webpage is not on a server, its on a laptop without any connection to the internet. The plan is for all that data to be written on to a text document.

My question is; can I send the first variable to a JavaScript like var = get.element... and then redirect the user to the second page where more variables get sent to the same JavaScript without the first disappearing. Because from what I have understood, all the scripts and variables "reset" when reloaded.

Extra, this is how I plan to write the info in a text file, does it look good or is there a better way to store data locally?

<?php
function createFile(){
    $file = 'D:\test.txt';
    // Open the file to get existing content
    $current = file_get_contents($file);
    // Append a new person to the file
    $current .= "John Smith
";
    // Write the contents back to the file
    file_put_contents($file, $current);
}
?>

Thanks for all your time!

  • 写回答

1条回答 默认 最新

  • dongxian6285 2013-12-01 13:09
    关注

    I would think to pass some parameters from the first page using GET or POST request to the second page.

    For example:

    //yourApp/second_page.php?name=John Smith
    

    is requested from the first page so you can get the data in the second page using $_GET['fname']

    The solution @shadow proposed (using html5 local storage api) seems more clean and simple tho.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?