Hello,

I want to click the skip ad buttom when the buttom appears, can someone please explain me how this can be done using jquery?

Here is the Code

<!DOCTYPE html>
<html>
<body style="margin:0px;padding:0px;">

<iframe src="http://bc.vc/7VsNj6" style="width:100%; height:100%; border:none;" id="frame">
  <p>Your browser does not support iframes.</p>
</iframe>

</body>
</html>

Thanks in advance.

Troy III commented: A correct & working code has been given to you - you need to say "THANK YOU!" and mark your thread as "Solved!" -2

Dani AI

Generated

Short summary (important constraint)
If the skip button is inside an iframe that loads a different domain (the OP’s iframe points to an external shortener), browser Same Origin Policy prevents any script in the parent page from reaching into that frame and clicking elements. Attempts to read the iframe document will produce a cross‑origin error in the console. That means a pure “parent page JavaScript” solution will not work for cross‑origin frames.

Suggested approaches (pick one that fits the control you have)

  • Inject code inside the framed page (best when the script can run in the same origin): install a userscript or browser extension so the code executes in the frame context. Prefer a MutationObserver to wait for the skip button instead of simple timeouts; that handles variable delays and dynamic insertion.

Example (run inside the page that contains the button — userscript / extension context)

(function waitAndClick(selector, timeoutMs) {
  const stopAt = Date.now() + timeoutMs;
  const tryClick = () => {
    const el = document.querySelector(selector);
    if (el) { el.click(); return true; }
    return false;
  };
  if (tryClick()) return;
  const obs = new MutationObserver(() => { if (tryClick()) obs.disconnect(); });
  obs.observe(document, { childList: true, subtree: true });
  setTimeout(() => obs.disconnect(), timeoutMs);
})('.skip, .skip-ad, #skip-button', 30000);
  • If both pages can be edited (cooperating domains): use window.postMessage from the iframe to notify the parent when the skip button appears or is ready. The parent can then act without trying to read the frame DOM.

Practical notes, pitfalls and tie‑ins to thread posts

  • As suggested, code injection requires a mechanism (userscript/extension) or hosting the content same‑origin.
  • is correct that timeouts work, but polling with fixed delays is brittle; MutationObserver is more reliable.
  • ’s quick one‑liner is a handy quick test but fragile for production.
  • Programmatic clicks may still not trigger behavior that demands a real user gesture (some ad/player APIs distinguish synthetic events). Also consider terms of service and security risks before automating interactions with third‑party ad frames.

Recommended Answers

All 3 Replies

There are no links in the code provided.

In any case, I assume what you mean is that you are visiting a web page and you want that link to be clicked automatically.

What is your plan to do this? Use some type of browsing app that let's you inject your own client side code?

Please elaborate and clarify.

I wrote you this:

;(function f(){find("skip ad")?getSelection().anchorNode.parentElement.click():setTimeout(f,1000)})();

copy-paste it on the page that needs to skip the ad and tell us how it went.

More info on Javascript timing events can be found here. I guess you could use the setTimeout() function. E.g.:

var timeout_time_in_seconds = 10;
var timeout = setTimeOut(function()
{
    //* Type here what needs to happen after the timer times out.

}, (1000 * timeout_time_in_seconds));
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.