views:

32

answers:

1

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  A: 

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?

bobince