My link looks like this:
http://localhost:8081/wordpress/?p=535
How can I redirect to this page with JavaScript? I’m unfamiliar with the ? syntax, but I have a feeling I should be able to send some sort of request with the ID of the post?
Something like:
redirect("p="+postid);
Just calling window.Location won’t work for me because if the post doesn’t exist, then I want to be able to do something else. Also, I don’t want it to direct to local host. It needs to direct to the root of the website…
More like this then:
if (request("p="+postid) exists) {
redirect("p="+postid);
}
If you want to check if the page exists first, you could do this :
This will make a HEAD request (so no content download) to check if the page exists and only change the current location if it’s OK.
Note that you may do that without jQuery if you want, I let you determine the exact syntax if needed.
But this can only work if both page are from the same domain.