Created
December 12, 2010 17:49
-
-
Save pcg79/738207 to your computer and use it in GitHub Desktop.
Using jQuery to manipulate Interstitial page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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