Jquery在尝试添加url参数时添加哈希符号


Jquery add hash sign when try to add url params

当我试图用location.hash在现有url中添加新参数时,我遇到了问题。添加新的两个参数后,散列符号自动添加到url #

我有链接:点击http://work.example.rs/index.php/profile/photos打开新的模式窗口,在那里我加载全尺寸图像并向url添加新的参数,如photo_idphoto_guid

preview: function() {
    $('body').on('click', '#open-picture-modal', function (e) {
        e.preventDefault();
        var $this = $(this);
        var guid = $this.data('guid');
        var photo_id = $this.data('id');
        var url = baseurl + '/picture/preview/?pgid='+guid+'&pid='+photo_id;
        location.hash = "&pgid="+guid+"&pid="+photo_id; // <-- Here is line 
    });
},

打开模式url更改如下后:http://work.example.rs/index.php/profile/photos#&pgid=E10B6F66-9686-9E29-55BA-3C197004F608&pid=6

在这个url中,你可以看到添加了#的url,我不知道是什么?

Html:

<?php $image_path = upload_userdata_url() .'/'. $photo->owner_id .'/'.'photos/'.$photo->photo_guid .'/'. $photo->photo_name;?>
<a href="<?= $image_path;?>" class="thumbnail" data-guid="<?= $photo->photo_guid; ?>" data-id="<?= $photo->photo_id; ?>" id="open-picture-modal" data-gallery>
<div class="uiMediaThumbImg" style="background-image: url(<?=$image_path;?>);"></div>
</a>

您使用的是hash,它将#符号附加到url。您可以使用HTML5 提供的历史API

更换线路

location.hash = "&pgid="+guid+"&pid="+photo_id;

window.history.pushState('', '', "&pgid="+guid+"&pid="+photo_id);