43792

How to use hidden iframe connect to the server in GreaseMonky

Question:

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

Answer1:

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?

Recommend

  • expand data frames inside data frame
  • GStreamer: status of Python bindings and encoding video with mixed audio
  • How is factorial computed?
  • Data manipulation on multiple dataframes in R
  • Sending signal to thread from annother non-process and logging stack not happening
  • Multiple Actionscript 3 layers
  • Alsa api: how to use mmap in c?
  • pure javascript dom dynamic insert, update and delete
  • byebug, next into application code only
  • After converting my FBX file to a .gltf, the model is incredibly small, why?
  • twisted.internet.error.ConnectError when run scrapy spider
  • jParallax trouble
  • Symfony2 redirect to https route fails (uses wrong port)
  • Can a variable be stored within an image or div tag?
  • Get variable height for a UIButton for iPhones 5/6/6+
  • PostgreSQL 9.x - pg_read_binary_file & inserting files into bytea
  • Why does the following throw an “Object doesn't support property or method 'importNode
  • Making header act like google chrome mobile app address bar
  • PayPal API Listener Website Payments Standard URI
  • Python ImageIO Gif Set Delay Between Frames
  • as3-flash: any way to access all the instances placed in different frames from document class?
  • Alternative To body {overflow:scroll;} That Will Prevent Page Jostling/Wriggling?
  • Blackberry - Custom EditField Cursor
  • Custom validator control occupying space even though display set to dynamic
  • Play WS (2.2.1): post/put large request
  • Change multiple background-images with jQuery
  • Body moving without any force applied? (Box2d)
  • Update CALayer sublayers immediately
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Why doesn't :active or :focus work on text links in webkit? (safari & chrome)
  • Change an a tag attribute in JavaScript based on screen width
  • How to show dropdown in excel using jrxml (jasper api)?
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • Android Google Maps API OnLocationChanged only called once
  • python draw pie shapes with colour filled
  • How to Embed XSL into XML
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?