Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
94
rated 0 times [  101] [ 7]  / answers: 1 / hits: 27299  / 16 Years ago, mon, march 2, 2009, 12:00:00

Is there an easy way to have JavaScript mimic a User clicking an anchor tag on a page? That means the Referrer Url needs to be set. Just setting the document.location.href doesn't set the Referrer Url.



<script>
$(document).ready(function () {
$(a).click();
});
</script>

<a href=http://example.com>Go here</a>


This doesn't work because there isn't a Click() event setup for the link.


More From » jquery

 Answers
42

You could do:



window.location = $(a).attr(href);


If you want to keep the referrer, you could do this:



var href = $('a').attr('href');
$('<form>').attr({action: href, method: 'GET'}).appendTo($('body')).submit();


It is hackish, but works in all browsers.


[#99901] Wednesday, February 25, 2009, 16 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jalyn

Total Points: 173
Total Questions: 96
Total Answers: 90

Location: Somalia
Member since Mon, Feb 27, 2023
1 Year ago
;