0

enter image description here

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

4 Answers 4

1

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];
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

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);

1 Comment

Thanks @Anton, if you don't mind can you please give me some small kind of tutorial for this, I'm still beginner . I mean where to add up these lines.
0

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;

3 Comments

Thanks @ It worked ! and it split the url after '?' Can you please tell how to redirect the user to that splited url . I mean how to redirect them to 'var link' when they click .
It redirects to parents directory actual url :www.myexample.com/rd/donate.html?www.anothersite.com but it redirects to www.myexample.com/rd/www.anothersite.com i need : www.anothersite.com only
@ShaymMurmu You need to http before the url try my code now. I have updated it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.