search

Home  >  Q&A  >  body text

javascript - I want to remove iframe ads, but every time the ID value is refreshed, the following five English characters are changing?

$("#iframe's ID").contents().find("#iframe's advertising ID").remove()
Originally, this code was used to remove ads that reference iframe, but each page The advertising id is updated as soon as it is refreshed. Cpg23241154qzkmv Cpg23241154ustep Cpg23241154gvhzk How to write to make this ID dynamic.

我想大声告诉你我想大声告诉你2817 days ago688

reply all(3)I'll reply

  • 迷茫

    迷茫2017-05-16 13:13:14

    It seems that its ID is quite regular, basically starting with "Cpg", then the processing is as follows

    $("#iframe的ID").contents().find('[id^="Cpg"]').remove();

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-16 13:13:14

    This kind of direct query for iframes excludes those in your own site and blocks all others, or you can determine whether the name of the iframe meets a certain rule and then block it

    reply
    0
  • 黄舟

    黄舟2017-05-16 13:13:14

    If you can find a pattern, write a regular rule

    It starts with Cpg, the middle 8 characters are always numbers, and the last 5 characters are lowercase letters:

    ^Cpg\d{8}[a-z]{5}$

    Start with Cpg23241154, the last 5 are numbers or letters:

    ^Cpg23241154\w{5}$

    reply
    0
  • Cancelreply