2017-10-15 87 views
0

我们在运行天气图的办公室中有一个屏幕。地图在iframe中运行,并设置为每小时刷新一次。这是代码;iframe键盘按钮按下页面加载

<!DOCTYPE html> 
 
<head> 
 
<title>VentuSky Barco Display</title> 
 
<link rel="icon" type="image/png" href="favicon.ico"> 
 
<meta http-equiv="refresh" content="3600"> 
 
</head> 
 
<iframe src="https://www.ventusky.com/?p=53.2;-9.7;4&l=rain-1h" style="position:fixed;top:0px;left:0px;bottom:0px;right:0px;width:100%;height:100%;border:none;margin:0;padding:0;overflow:hidden;z-index:999999"></iframe>

在VentuSky映射在iframe坐镇,如果用户按下键盘上的“P”,它隐藏所有的菜单,只是显示在地图(或“演示模式”,正如VentuSky所称的那样)。

有没有什么办法让浏览器在每小时刷新一次时自动执行此操作?

+0

你试过我的解决方案吗?它有用吗? – Dmitry

回答

0

由于安全原因,浏览器禁止从另一个域访问iframe,因此无法直接从此代码执行此操作。但您可以使用FireFox的Grease Monkey等浏览器插件。

解决方案FireFox和油猴:

  1. 安装Firefox和油猴
  2. 按字形的通用图标(1)附近,选择New User Script(2) enter image description here
  3. 名称脚本“ ventusky”
  4. 输入命名空间:https://www.ventusky.com/ enter image description here
  5. 将以下代码粘贴到该窗口将打开:

    // ==UserScript== 
    // @name  ventusky 
    // @namespace https://www.ventusky.com/ 
    // @description trigger p key press in https://www.ventusky.com/ 
    // @version  1 
    // @grant  none 
    // ==/UserScript== 
    window.onload = function() 
    { 
        var keyboardEvent = document.createEvent("KeyboardEvent"); 
    
        keyboardEvent.initKeyEvent(
         "keydown", // event type : keydown, keyup, keypress 
         true, // bubbles 
         true, // cancelable 
         window, // viewArg: should be window 
         false, // ctrlKeyArg 
         false, // altKeyArg 
         false, // shiftKeyArg 
         false, // metaKeyArg 
         'P'.charCodeAt(0), // keyCodeArg : unsigned long the virtual key code, else 0 
         0 // charCodeArgs : unsigned long the Unicode character associated with the depressed key, else 0 
        ); 
        document.dispatchEvent(keyboardEvent); 
    }; 
    

注:它会要求你输入“允许粘贴”当您尝试粘贴代码。

按键事件触发代码是基于this的答案。