A couple of things spring to mind.
1. Instead of redirecting to a new internal page first, just redirect the page to itself, but include the url parameter in the redirect, then add the conditional javascript in the head section.
2. If this doesn't fulfil your needs, can you store whatever values you need in a session variable ?