0

i have page with iframe. this is the page:

<script>
$(".search").on("click", function() {
    var iframe = $("#frame");
    var msg = "test";
    iframe[0].contentWindow.$('body').trigger("search", msg);
});
</script>
<a href="javascript: void(0);" class="search">
<iframe src="window.html" id="frame" width="500" height="500">

when i click search button its send trigger to my iframe page.

this is my iframe page:

<script>
    $(document).ready(function(){
        $("body").on("search", function(e, msg) {
            window.find(msg);
        });
    });
</script>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's test test standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled test it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>

the listener to the trigger in my iframe running window.find() function with the msg that i sent. every thing good.

the problem its when its running window.find() its scrolling the iframe to the position its found the text but its scrolling the parent window too why? i want the its will scroll only the iframe window... what can i do to prevent scrolling on my parent window?

there is option to prevent window.find() auto scrolling at all?

tnx a lot

kfir
  • 732
  • 10
  • 22
  • Few of the many options is restricting the parent scroll using css like `overflow: hidden` and iframe to be only the scrollable part (not sure about your page so can't really say if it would work) other option is either https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-snap-type or https://css-tricks.com/almanac/properties/o/overflow-anchor/ – Sumit Surana Dec 06 '20 at 16:40
  • @sumit but i have scroll in the parent ... and i need him i only want the when i using window.find in my iframe the parent window no "jump" too. – kfir Dec 06 '20 at 17:22
  • have a look at https://stackoverflow.com/questions/64288173/how-to-disable-auto-scrolling-when-using-window-find-inside-an-iframe. From what I understand `window.find` auto scroll is very browser specific and to avoid scrolling of parent you would need to disable the scroll while you are finding the string in iframe for parent either by js or CSS – Sumit Surana Dec 07 '20 at 16:47

0 Answers0