dongzhong5967 2017-08-01 05:48
浏览 66

php / html使用URL的文本作为变量信息? [重复]

This question already has an answer here:

I have a html page, and php script that is action of a form on the html page. I want to be able to get the last bit of text after the hash of the previous url (from the html page)

www.website.com/htmlpage#token5

So that I get just have the string: "token5" placed into a varible so that when I submit the html form, the PHP script gets the previous URL or something on those lines, to be able to get this string.

something like:

1. submit form from www.website.com/htmlpage#token5
2. action of form goes to www.website.com/phppage
3. php page gets the "token5" string.

How would I go about doing this? thanks`

</div>
  • 写回答

3条回答 默认 最新

  • dongpan5289 2017-08-01 05:53
    关注

    You could use JavaScript to get the hash and latter add it to your form element.

      if(window.location.hash) {
          var hash = window.location.hash.substring(1); //Puts hash in variable, and removes the # character
          // do whatever you want to do with hash
      } else {
          // No hash found
      }
    
    评论

报告相同问题?