Reputation: 11
Once my page load a unique link is generated through a third party application, I need that stored in a variable to be accessed later.
How do I set the link as a variable, AND how do I make sure it is done AFTER the page has been loaded?
Code generated by third party application:
<div class="_ohe lfloat"><a href="THE LINK TO BE SET GENERATES HERE" src=".jpg" target="_blank" class="img _8o _8s UFIImageBlockImage"><img class="_1ci img" src="https://scontent.ftpa1-1.fna.fbcdn.net/v/t1.0-1/p48x48/12472831_1760775617477649_5525707532693192482_n.jpg?oh=32736fd5787e04e6f55aa8eb7ecaa529&oe=59539C06" alt=""></a></div>
Upvotes: 0
Views: 5749
Reputation: 33933
To store the href
of a link in a variable after page load:
EDIT: Add an interval to get the value if it is appended slightly after load.
$(document).ready(function(){
var myHref = "";
// Set an interval to check cyclically for the presence of href
var waitForTheHref = setInterval(function(){
// Look for the value
myHref = $(document).find("._ohe.lfloat a").attr("href");
// Check if the value is present
if( myHref !== "" && myHref !== "undefined"){
// Show it in console
console.log(myHref);
// You have the value... Clear the interval!
clearInterval(waitForTheHref);
}
},50); // milliseconds.
});
Upvotes: 2