使用URL时转换为十六进制.文档或window.location.href

Curly Brackets Converted to Hexidecimal when using URL.Document or window.location.href

本文关键字:window location href 文档 十六进制 URL 转换 使用      更新时间:2023-09-26

要取文档。URL,找到带花括号的字符串,去掉花括号,只显示在花括号内的字符串。然而,似乎文件。URL或window.location.href将花括号转换为十六进制值(%7B &%7D),然后我无法匹配实际的{string}。如有任何帮助,不胜感激。

  var txt = document.URL; // My URL is something like http://site.com/somepage&value0={string}
  var re1='.*?';    // Non-greedy match on filler
  var re2='(''{.*?''})';    // Curly Braces 1
  var p = new RegExp(re1+re2,["i"]);
  var m = p.exec(txt);
  if (m != null)
  {
      var cbraces1=m[1];
      document.write(cbraces1.replace("{","").replace("}",""));
  }

先用decodeURI(document.URL)

var txt = decodeURI(document.URL);
unescape('%7B & %7D');