我能停止一个iframe在加载之前吗?

huangapple go评论76阅读模式
英文:

can i stop a iframe, before it is loading?

问题

以下是翻译好的部分:

我有一些包含不同Google地图嵌入(iframe)的网站。在过去的几个月里,我阅读了很多关于数据保护和隐私政策的内容。与Google地图相关的风险很多。
现在我想为用户使用一个验证按钮,以在加载Google地图之前获得他们的同意。

我会使用jQuery来实现这个功能。
我的想法是删除iframe的src并显示一个警告通知,内容类似于:“如果您继续点击,您将接受Google地图的隐私政策,请查看这里”。

点击按钮后,地图将被加载。

我的解决方案:

  1. jQuery -> document.ready -> 循环查找所有iframe -> 检查是否为Google地图 -> 将src URL保存在变量中或写入iframe标签的数据标签中 -> 显示警告通知

  2. 如果点击按钮,则从数据标签或变量中获取src,将其设置为iframe的src并加载地图。

但是...我不确定这是否足够“快速”。
如果有人打开我的网站,触发document.ready事件可能需要几秒钟,加载整个网站也需要一些时间...在我的循环清除iframe的src之前,是否可能使iframe加载Google地图并发送一些个人数据?

谢谢您的帮助。

英文:

I have some websites with different google maps embeds.(iframe) I read a lot of about data protection and privacy policy in the last few month. There are a lot of risk in relation with google maps.
Now i want to use a validation button for the user, before the google maps are loaded.

I'll do that with jQuery.
My idea is to delete the src from the iframes and show a warrning notice like "If you click continue, you will accept the google maps privacy policy. see here"

after click the button, the maps are loaded.

My solution:

  1. jQuery -> document.ready -> loop to find all iframes -> check if google maps -> save src url in a variable or write it in a data-tag from the iframe tag -> show warning notice

  2. if click on button, get src from data tag, or variable. set it as src for the iframe and load the map.

BUT... I'm not sure if it is "fast" enough.
If someone open my site, i does take a few seconds for trigger the document.ready event and some seconds again, for loading the whole site... Is it possible, that the iframe loads the google maps and send some personal data, before my loop clear the src from the iframe????

thank you for your help

答案1

得分: 0

在你的HTML代码中,你可以将iframe的src属性设置为空值:

<iframe id="mapFrame" src=""></iframe>

然后,在你的jQuery代码中,当用户点击验证按钮时,你可以将Google Maps的URL分配给src属性:

$(document).ready(function() {
  // 存储Google Maps的URL
  var googleMapsURL = "https://maps.google.com/your-maps-url";

  // 最初移除src属性
  $("#mapFrame").attr("src", "");

  // 显示警告通知并处理按钮点击
  $("#validationButton").click(function() {
    // 将Google Maps的URL设置为src属性
    $("#mapFrame").attr("src", googleMapsURL);
  });
});
英文:

in your HTML code, you can set the src attribute of the iframe to an empty value:

&lt;iframe id=&quot;mapFrame&quot; src=&quot;&quot;&gt;&lt;/iframe&gt;

Then, in your jQuery code, you can assign the Google Maps URL to the src attribute when the user clicks on the validation button:

$(document).ready(function() {
  // Store the Google Maps URL
  var googleMapsURL = &quot;https://maps.google.com/your-maps-url&quot;;

  // Remove the src attribute initially
  $(&quot;#mapFrame&quot;).attr(&quot;src&quot;, &quot;&quot;);

  // Show warning notice and handle button click
  $(&quot;#validationButton&quot;).click(function() {
    // Set the Google Maps URL as the src attribute
    $(&quot;#mapFrame&quot;).attr(&quot;src&quot;, googleMapsURL);
  });
});

huangapple
  • 本文由 发表于 2023年5月25日 23:32:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76333998.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定