B. Dionys B. Dionys - 1 year ago 66
HTML Question

How to get a automaticaly clicked link with javascript

I created a button that links to rederect.html and in there i created a link using

<a href>
that has to be auto-clicked to go to index.html.

So when you are on index and used the button to get there you go to the rederect.html and automatically go back to index.html because the a
has to auto-trigger. The only problem is that the
<a href>
does not auto-trigger.

This is what i got so far:

<a href="index.html" class="banan" id="banan">Succesvol uitgelocht return naar login.</a>

<script type="text/javascript">
window.onload = function() {
window.location.href = $('.banan').attr('index.html');

I used the
event to try and trigger the function in there to trigger when you get on the redirect page. but it does not autorederect/click the
<a href>
or give back any errors so i really don't know how to fix this. I searched some 4 hours on this subject and tried a lot of things but none did really help.
(sorry for my bad english i'm not very good at the language, i hope it is understandable what i tried to ask)

Answer Source

To get the attribute's value by using the function .attr you need to pass the attribute name which is href.

The .attr() method gets the attribute value for only the first element in the matched set


window.location.href = $('.banan').attr('href');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download