2016-03-30 67 views
-4

我有問題,當我嘗試在location.hash現有的網址中添加新的參數。增加新的兩個參數後哈希符號全自動添加到URL #當嘗試添加網址參數時Jquery添加散列符號

我有鏈接:http://work.example.rs/index.php/profile/photos上點擊我打開其中i加載最大尺寸的圖像,並添加新的參數去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 #加入我不知道whay?

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> 
+2

你知道是什麼'hash'是什麼? https://developer.mozilla.org/en/docs/Web/API/Window/location – llamerr

+0

也你的PHP代碼看起來不像HTML,如你所說,如果你想發佈HTML - 只需發佈HTML瀏覽器 – llamerr

+0

https ://en.wikipedia.org/wiki/Fragment_identifier – llamerr

回答

1

您正在使用hash其中#符號追加到URL。通過HTML5

可以用戶提供History API更換您的行

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

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