Skip to content

Instantly share code, notes, and snippets.

@pcg79
Created December 12, 2010 17:49
Show Gist options
  • Save pcg79/738207 to your computer and use it in GitHub Desktop.
Save pcg79/738207 to your computer and use it in GitHub Desktop.
Using jQuery to manipulate Interstitial page
<script type="text/javascript">
$(document).ready(function() {
var href = $("#redirect_url")[0].href;
$("a#replace_me").attr("href", href);
$("a#replace_me").text(href);
$("#redirect_to").hide();
});
</script>
<p>Greetings. We are now redirecting you to the site that you requested.</p>
<p><a id="replace_me"></a></p>
<p>Have a great day!</p>
----
A quick jQuery tutorial:
$(document).ready
runs when all the elements on the page have loaded.
var href = $("#redirect_url")[0].href;
gets the first element whose ID is "redirect_url" and gets the "href" attribute. Since it's an <a> tag the href attribute is the URL.
$("a#replace_me").attr("href", href);
sets the "href" attribute of the <a id="replace_me"> tag to the variable href.
$("a#replace_me").text(href);
sets the text of the <a id="replace_me"> tag to the variable href. The text is what's inside the <a> tags. <a>This is the text</a>
$("#redirect_to").hide();
hides the <p id="redirect_to"> tag
As a note, if you use the Firefox browser you can use the Firebug plugin (http://getfirebug.com/) to easily view the elements of the interstitial page and execute JavaScript on the page directly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment