Reputation: 3
As mentioned above, i need to create a class="donate"
that will be used in anchor tag which will redirect and pass the value of href
to my another page i.e -mysite.com/donate.html,
where donate.html will be able to grab that href
value .
so that when user click on " continue to download" will be able to download the
file .
Please let me know whether is it possible or not . I would prefer HTML and javascript only . as I don't host webpages i use blogger .
I've seen similar concept in templateism.com, something like:
www.templateism.com/p/preview.html?=www.templateism.com/10/2010/anypost.html
Upvotes: 0
Views: 3269
Reputation: 4275
Here try this For example...... This is your html code
<a href="http://example.com/donate.html?www.yoursite.com.otherpage.html"></a>
As Ashkan said, use his javascript to parse the previous url from it... Paste this code on donate.html
<script>
var href = document.location.href;
var link = href.split('?')[1];
window.location.href = "http://"+link;// This will show you the link
</script>
Hope this helps;
Upvotes: 0
Reputation: 2636
You can use the JavaScript (jQuery required) code below to attach a click event handler to all links with the donate
class.
JS on page1.html and page2.html
$(document).ready(function() {
$('a.donate').click(function() {
// Retrieve the href value and store it in a variable.
var href = $(this).attr('href');
// Redirect a user to the desired page and passes the href value in query string.
window.location.href = 'http://example.com/donate.html?href=' + href;
// Ensure the original click event handler is not triggered.
return false;
})
});
After clicking a link the user will be redirected to the donate page where you can parse the query string and obtain the value of the href
(which is what was in the <a href="...">
on the previous page).
There are many ways to parse the query string but the following quick&dirty code should work for you.
JS on donate.html
var location = document.location.href;
var queryString = location.split('?')[1];
// In the href variable is now what you are looking for.
var href = queryString.substr(5);
Upvotes: 0
Reputation: 34150
you can use the link like:
mysite.com/donate.html?www.yoursite.com.otherpage.html
and then using javascript:
var href = document.location.href;
var link = href.split('?')[1];
Upvotes: 1
Reputation: 499
Basically you need to pass the value you required in querystring like mysite.com/donate.htm?key=value.
On donate.htm page you can use this function mentioned here How can I get query string values in JavaScript? to fetch the value you supplied in querystring by passing the key.
Upvotes: 0