0

I have a page which shows some data from a database. Each of these data rows has a link with an ID.

<a href="javascript:void(0);" onClick="changeUrl(\'?side=annoncer&sletid='.$row['annonce_id'].'\');"> 

This is the changeUrl function:

function changeUrl(url) { window.history.replaceState(null, "Title", url); } 

The link points to the same page, with &sletid added. When &sletid is set, the page should do a popup with the ID of the selected row.

if (isset($_GET['sletid'])) { $sletid = $_GET['sletid']; echo "<script language='JavaScript'>alert ('ID:".$sletid."');</script>"; } 

The URL changes, and the popup script code is added to the source, but the popup doesn't show unless I manually update the page again. Why this behavior?

1
  • maybe you should use a button instead of a, if it's really not a link at all Commented Aug 7, 2012 at 14:40

2 Answers 2

1

replaceState doesn't actually load the page, it just edits the history (and the location bar) in the browser. You need to load the page yourself using AJAX.

Sign up to request clarification or add additional context in comments.

Comments

0

Your phpcode doesnt get executed because the change of the history state just affects the client side. You need to listen to the change of the history on the client side.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.