How to use hidden iframe connect to the server in GreaseMonky

若如初见. 提交于 2020-01-06 05:28:04

问题


First,I created a hidden frame like this:

var oHiddenFrame = null;
if(oHiddenFrame == null){
  oHiddenFrame = document.createElement("iframe");
  oHiddenFrame.name = "hiddenFrame";
  oHiddenFrame.id = "hiddenFrame";
  oHiddenFrame.style.height = "0px";
  oHiddenFrame.style.width = "0px";
  oHiddenFrame.style.position = "absolute";
  oHiddenFrame.style.visbility = "hidden";
  document.body.appendChild(oHiddenFrame);
}

Then,I add a event to the button like this:

var fnLocation = function(){
    frames["hiddenFrame"].location.href = "http://meckmeck.cn";
}

var oButton = document.getElementById("mb_submit");
oButton.addEventListener("click", fnLocation, false);

When I click the button,I got a error:

frames.hiddenFrame is undefined

回答1:


There's no such thing as document.frames. The name-indexed frame array is window.frames (aka just frames).

0-iframes are so old-school, and these days mostly associated with malware-installing exploits (especially on Chinese pages). How about using an XMLHttpRequest instead?



来源:https://stackoverflow.com/questions/1666860/how-to-use-hidden-iframe-connect-to-the-server-in-greasemonky

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!