admin 管理员组文章数量: 1086019
So, I have a javascript for a popunder ad, (yeah I know they're annoying but it's not an ad, it's a page that opens behind the main page) anyway, because the script has the page open automatically when you go to my page, pop up blockers automatically block it, so what I would like to do is have the script run when someone clicks a link on my page, therefore it is user initiated and not automatically, so it doesn't get blocked by a popup blocker.. basically, so when someone clicks on one of the links on my page, it opens the link, but also opens the pop under behind my page.. I'm kind of new to javascript, but any help is appreciated!
So, I have a javascript for a popunder ad, (yeah I know they're annoying but it's not an ad, it's a page that opens behind the main page) anyway, because the script has the page open automatically when you go to my page, pop up blockers automatically block it, so what I would like to do is have the script run when someone clicks a link on my page, therefore it is user initiated and not automatically, so it doesn't get blocked by a popup blocker.. basically, so when someone clicks on one of the links on my page, it opens the link, but also opens the pop under behind my page.. I'm kind of new to javascript, but any help is appreciated!
Share Improve this question edited Jul 3, 2013 at 7:07 AntouanK 4,9881 gold badge23 silver badges26 bronze badges asked Jul 3, 2013 at 7:01 BrendanMann_1BrendanMann_1 111 gold badge1 silver badge2 bronze badges 2-
2
Whats the
onClick
event for? – Mr. Alien Commented Jul 3, 2013 at 7:02 - There isn't an onClick event, atleast I don't think so... 2createawebsite./enhance/create-popunder.html is where I got the script from, so if you see anything in there that I didn't it would be really helpful – BrendanMann_1 Commented Jul 3, 2013 at 7:06
4 Answers
Reset to default 4This would be one approach:
HTML:
<a id="link">Link</a>
JavaScript:
function script() {
alert("I'm the ad");
};
document.getElementById('link').onclick = function () {
script();
};
For demonstration see this Fiddle.
/Edit: Sure, here is the JavaScript:
// copy and paste the script from the website
document.getElementById('open').onclick = function () {
load_pop_power();
};
If you don't want to show the ad when the user visits the site, you could however delete half of the code.
You could do something like this
function doSomething() {
//do your actions here
window.location="http://www.gotothelink.";
}
</script>
<a href="javascript:doSomething();">click me</a>
When the user clicks the link, the javascript code in the "onlick" attribute is executed. "window.open" opens a new window and "return true" has the effekt that the normal behaviour of the link keeps working.
<a href="http://www.tiscover." onclick="window.open('http://www.tiscover.'); return true;">tiscover</a>
So you need to bind the popunder to a click event on a link see http://www.pagecolumn./javascript/bind_event_in_js_object.htm
本文标签: javascriptHow to run a script when clicking on a linkStack Overflow
版权声明:本文标题:javascript - How to run a script when clicking on a link? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744002710a2516739.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论