2013-10-29 2 views
-2

url에서 해시 태그를 찾고 php를 사용하여 해당 url에서 마지막으로 추가 할 수있는 솔루션이 필요합니다.url에서 해시 태그를 찾고 해당 URL에서 php를 사용하여 마지막에 추가하십시오.

올드 URL :http://www.example.com?q=123123#anchor1?name=shreyas&city=surat

새로운 URL은 :http://www.example.com?q=123123&name=shreyas&city=surat#anchor1

+1

'window.location.search = + window.location.search하면 window.location.hash; ' – adeneo

+1

@adeneo'window.location.hash'도 쿼리 문자열을 포함합니다. – levi

답변

1
var url = 'http://www.example.com#anchor1?name=shreyas&city=surat'; 
var hash = /#[^?]+/.exec(url)[0]; 
url = url.replace(hash, '') + hash; 

Jsfiddle

0

또한이 시도 할 수 있습니다.

HTML :

<a href="http://www.example.com#anchor1?name=shreyas&city=surat">My Url</a> 

jQuery를 :

var url= $("a").attr("href"); 
//get the subString matching that pattern "#...?" 
var subUrl = url.match("\#[A-Z]*[a-z]*[0-9]*"); 
// removes the subString that matches the pattern "#...?" 
url= url.replace(/\#[A-Z]*[a-z]*[0-9]*/, ''); 
//final url 
url= url+ subUrl; 
//updating it 
$("a").attr("href", url); 

jsFiddle Demo

+0

고마워요 선생님 .. :) –

관련 문제