Javascript 在链接上运行函数,将用户发送到预链接广告页面,广告页面在5秒后重定向用户

Javascript 在链接上运行函数,将用户发送到预链接广告页面,广告页面在5秒后重定向用户,javascript,jquery,Javascript,Jquery,在页面上有一组链接,如下所示: <a class="wsite-button wsite-button-large wsite-button-highlight" href="/uploads/7/0/9/4/70947887/custom_themes/436120861689278040/files/Games/17waystokillboss.swf" id="link" onclick="doalert(); return false;><span class="ws

在页面上有一组链接,如下所示:

<a class="wsite-button wsite-button-large wsite-button-highlight"  href="/uploads/7/0/9/4/70947887/custom_themes/436120861689278040/files/Games/17waystokillboss.swf" id="link" onclick="doalert(); return false;><span class="wsite-button-inner">17 Ways To Kill Your Boss(NEW)</a><br>
<a class="wsite-button wsite-button-large wsite-button-highlight"  href="/uploads/7/0/9/4/70947887/custom_themes/436120861689278040/files/Games/24waystokyb.swf" id="link" onclick="doalert(); return false;><span class="wsite-button-inner">24 Ways To Kill Your Boss(NEW)</a><br>
<a class="wsite-button wsite-button-large wsite-button-highlight"  href="/uploads/7/0/9/4/70947887/custom_themes/436120861689278040/files/Games/4-wheel-madness.swf" id="link" onclick="doalert(); return false;><span class="wsite-button-inner">4 Wheel Madness</a><br> 
<a class="wsite-button wsite-button-large wsite-button-highlight"  href="/uploads/7/0/9/4/70947887/custom_themes/436120861689278040/files/Games/Achilles.swf" id="link" onclick="doalert(); return false;><span class="wsite-button-inner">Achillies(NEW)</a><br>
<a class="wsite-button wsite-button-large wsite-button-highlight"  href="/uploads/7/0/9/4/70947887/custom_themes/436120861689278040/files/Games/alien_hominid.swf" id="link" onclick="doalert(); return false;><span class="wsite-button-inner">Alien Hominid(NEWER)</a><br>
<a class="wsite-button wsite-button-large wsite-button-highlight"  href="/uploads/7/0/9/4/70947887/custom_themes/436120861689278040/files/Games/asteroids.swf" id="link" onclick="doalert(); return false;><span class="wsite-button-inner">Asteriods(NEW)</a><br>






运行此页面以发送到adpage的脚本:

<script>
function doalert() {
var str1 = "http://www.goldandblack.net/adpage.html#";

    window.location.href = str1.concat(document.getElementById("link").getAttribute("href")));
    return false;
};
</script>

函数doalert(){
变量str1=”http://www.goldandblack.net/adpage.html#";
window.location.href=str1.concat(document.getElementById(“link”).getAttribute(“href”));
返回false;
};
要转发到已单击页面的adpage上的脚本:

<script>
window.onload = function() {
var str2 = window.location.href;
var str3 = str2.replace("http://www.goldandblack.net/adpage.html#", "");
window.location.href = str3;
};

</script>

window.onload=函数(){
var str2=window.location.href;
变量str3=str2。替换(“http://www.goldandblack.net/adpage.html#", "");
window.location.href=str3;
};

由于某种原因,这不起作用

id
属性对于任何元素都应该是唯一的。因此,拥有所有元素将导致问题

您可以改为删除
id
属性,并将元素自身发送到
doalert()
函数,就像这样
doalert(this)

因此,您的html部分如下所示:

<a class="wsite-button wsite-button-large wsite-button-highlight" href="/uploads/7/0/9/4/70947887/custom_themes/436120861689278040/files/Games/17waystokillboss.swf" onclick="doalert(this); return false;"><span class="wsite-button-inner">17 Ways To Kill Your Boss(NEW)</a><br>
<a class="wsite-button wsite-button-large wsite-button-highlight" href="/uploads/7/0/9/4/70947887/custom_themes/436120861689278040/files/Games/24waystokyb.swf" onclick="doalert(this); return false;"><span class="wsite-button-inner">24 Ways To Kill Your Boss(NEW)</a><br>
<a class="wsite-button wsite-button-large wsite-button-highlight" href="/uploads/7/0/9/4/70947887/custom_themes/436120861689278040/files/Games/4-wheel-madness.swf" onclick="doalert(this); return false;"><span class="wsite-button-inner">4 Wheel Madness</a><br> 
<a class="wsite-button wsite-button-large wsite-button-highlight" href="/uploads/7/0/9/4/70947887/custom_themes/436120861689278040/files/Games/Achilles.swf" onclick="doalert(this); return false;"><span class="wsite-button-inner">Achillies(NEW)</a><br>
<a class="wsite-button wsite-button-large wsite-button-highlight" href="/uploads/7/0/9/4/70947887/custom_themes/436120861689278040/files/Games/alien_hominid.swf" onclick="doalert(this); return false;"><span class="wsite-button-inner">Alien Hominid(NEWER)</a><br>
<a class="wsite-button wsite-button-large wsite-button-highlight" href="/uploads/7/0/9/4/70947887/custom_themes/436120861689278040/files/Games/asteroids.swf" onclick="doalert(this); return false;"><span class="wsite-button-inner">Asteriods(NEW)</a><br>
<script>
function doalert(obj) {
    var str1 = "http://www.goldandblack.net/adpage.html#";
    window.location.href = str1.concat(obj.getAttribute("href"));
    return false;
};
</script>
<script>
window.onload = function() {
    var str3 = window.location.hash;
    str3 = str3.substring(1); // remove the first char from string
    window.location.href = str3;
};
</script>
您还可以通过以下行获取
Location散列属性:
window.Location.hash

然后,它将返回URL的锚定部分,其开头带有
#
。因此,我们得到它并删除开头的
#
字符

因此,
adpage.html
文件中的
脚本将如下所示:

<a class="wsite-button wsite-button-large wsite-button-highlight" href="/uploads/7/0/9/4/70947887/custom_themes/436120861689278040/files/Games/17waystokillboss.swf" onclick="doalert(this); return false;"><span class="wsite-button-inner">17 Ways To Kill Your Boss(NEW)</a><br>
<a class="wsite-button wsite-button-large wsite-button-highlight" href="/uploads/7/0/9/4/70947887/custom_themes/436120861689278040/files/Games/24waystokyb.swf" onclick="doalert(this); return false;"><span class="wsite-button-inner">24 Ways To Kill Your Boss(NEW)</a><br>
<a class="wsite-button wsite-button-large wsite-button-highlight" href="/uploads/7/0/9/4/70947887/custom_themes/436120861689278040/files/Games/4-wheel-madness.swf" onclick="doalert(this); return false;"><span class="wsite-button-inner">4 Wheel Madness</a><br> 
<a class="wsite-button wsite-button-large wsite-button-highlight" href="/uploads/7/0/9/4/70947887/custom_themes/436120861689278040/files/Games/Achilles.swf" onclick="doalert(this); return false;"><span class="wsite-button-inner">Achillies(NEW)</a><br>
<a class="wsite-button wsite-button-large wsite-button-highlight" href="/uploads/7/0/9/4/70947887/custom_themes/436120861689278040/files/Games/alien_hominid.swf" onclick="doalert(this); return false;"><span class="wsite-button-inner">Alien Hominid(NEWER)</a><br>
<a class="wsite-button wsite-button-large wsite-button-highlight" href="/uploads/7/0/9/4/70947887/custom_themes/436120861689278040/files/Games/asteroids.swf" onclick="doalert(this); return false;"><span class="wsite-button-inner">Asteriods(NEW)</a><br>
<script>
function doalert(obj) {
    var str1 = "http://www.goldandblack.net/adpage.html#";
    window.location.href = str1.concat(obj.getAttribute("href"));
    return false;
};
</script>
<script>
window.onload = function() {
    var str3 = window.location.hash;
    str3 = str3.substring(1); // remove the first char from string
    window.location.href = str3;
};
</script>

window.onload=函数(){
var str3=window.location.hash;
str3=str3.substring(1);//从字符串中删除第一个字符
window.location.href=str3;
};

函数doalert(obj){var str1=”“;window.location.href=str1.concat(obj.getAttribute(“href”);返回false;};此代码似乎有问题。这不是(“href”)中的额外偏执))很抱歉输入错误,我只是复制并粘贴了你的代码,没有看到多余的)。事实上,多余的)存在于你自己的代码中!我伪造了我的代码。谢谢你,不幸的是,我仍然收到一个语法错误。这一次,页面上的链接似乎有问题。这是我更新的代码:
好的,另一个输入错误,再次出现在你的源代码中最后的代码!在html的这个部分
onclick=“doalert(this);返回false;>缺少双引号!所以它应该是这样的:
onclick=“doalert(this);returnfalse;”>
。我已经编辑了我的答案并修复了它。您绝对不应该重复任何
id
属性的值。