کمک فوری در مورد کد جاوا

hannanstd.ir

مدیر انجمن و توسعه دهنده ووکامرس پارسی
سلام . من یه صفحه دارم به صورت زیر .


کد:
<html>

<a href="http://arshad98.ir/">clickme</a>

<html/>
حالا میخوام از طریق کد جاوا یا php که بهش اضافه میکنم کاری کنم که وقتی صفحه لود شد . به صورت خودکار هرچی تگ <a> توش هست ران بشه . یعنی وقتی صفحه لود شد انگار که یکی روی clickme کلیک کرده .

در ضمن کدی که لازم داره جوریه که فقط باید روی تگ a تاثیر بزاره ؛ نه روی آیدی و رو نخواد فراخونی کنه .

فقط تگ a

 
آخرین ویرایش توسط مدیر:

hannanstd.ir

مدیر انجمن و توسعه دهنده ووکامرس پارسی
تقریبا مشکلم حل شده اما یه مشکلی دارم چرا


کد:
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
                  document.getElementById("linkToClick").click();
}
</script>
</head>

<body onload="myFunction()">


<a href="http://www.google.com" target="_blank" id="linkToClick">GOOGLE</a>

</body>

</html>
کار میکنه ولی وقتی


کد:
getElementById("linkToClick")
رو با


کد:
getElementsByTagName("a")
عوض میکنم کار نمیکنه ؟ لطفا کمک کنین .

 

hannanstd.ir

مدیر انجمن و توسعه دهنده ووکامرس پارسی
بالاخره حلش کردم حالا اینجا هم میزارم شاید روزی به کار یکی اومد :


کد:
<!DOCTYPE html>
<html>
<head>
<script>
Element.prototype.anchorClick = function() {
    if (this.click) return this.click();
    if (this.onclick) { var result = this.onclick(); if (!result) return result; }

    switch (this.target) {
        case '_blank': window.open(this.href); break;
        case '_parent': parent.location = this.href; break;
        case '_top': top.location = this.href; break;
        case '_self': case '': window.location = this.href; break;
        default: if (parent[this.target]) parent[this.target].location = this.href; else window.open(this.href); break;
    }

    return true;
}

function myFunction() {
javascript:document.getElementsByTagName('a')[0].anchorClick();
}
</script>
</head>

<body onload="myFunction()">

<a href="http://www.google.com" id="linkToClick">GOOGLE</a>

</body>

</html>
 
بالا