【问题标题】:Is there a way to append a fragment to the current URL有没有办法将片段附加到当前 URL
【发布时间】:2015-05-03 07:58:39
【问题描述】:

我对 PHP 比较陌生,我想知道是否可以在 PHP 的服务器上使用 #something 修改当前 url(或者我猜是另一种语言;也许是 JavaScript)?

感谢您的帮助,

小盒子

【问题讨论】:

标签: javascript php url


【解决方案1】:

使用 javascript

window.location=window.location+'#something'

用php

$query = parse_url($url, PHP_URL_QUERY);
if ($query) {
    $url .= '#something';
}

【讨论】:

  • 20 分钟我一直在寻找 PHP 中的答案,这就是我所追求的... -.- 谢谢 :)
  • 我会的,要等几分钟
【解决方案2】:

另一种使用当前 URL 添加#something 的最简单方法

JS:

var e = "something";
     window.history.pushState(" ", "", "#" + e)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-11
    • 1970-01-01
    • 2021-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多