Jump to content

Can I call a function from inside a frame?


programmer-in-training

Recommended Posts

Is it possible for JavaScript in a frame to call JavaScript functions that are not in the frame, the parent window? I am displaying dynamically generated output inside an <iframe>. (For scrollability; if I knew of a way to get a <div> to scroll it, I would use it...)The content in the <iframe> has onMouseOver events that used to call functions in the parent window when it was a <div>, but now that I am using an <iframe> it gives an error (object expected).

Link to comment
Share on other sites

You can make a scrolling div, buy saying in the style of the div:

overflow:auto;

Tht is after of course you have defined a height and width...

Link to comment
Share on other sites

This is a very old school approach, but I believe it still works. In your frame set, give your frames names, like this:<frame src="frameA.html" name="frameA" />from frameB, call a function in frameA like this:parent.frameA.theFunction();

Link to comment
Share on other sites

Yes. Or you could just make your div's have a set height/width and give them the overflow:auto; CSS attribute... whichever works.

Link to comment
Share on other sites

Well I would be careful on the use of iframes because of the SEO issues, you'll have to work round the fact that the visitor can find your page alone which is only intended to appear within the iframe

Link to comment
Share on other sites

  • 1 month later...

Is there any way to get around these "Access denied" errors when you try to call a function running in a different frame/window? I think it's to stop illegal use of JavaScript, but I own both window and frame. (My main site and my blogspot.com site) I would like them to communicate, but nothing works.Does anyone know if I can somehow verify that I am the real owner and am allowed to do this?

Link to comment
Share on other sites

No, there's no way, not with Javascript.The reason is simple: I can execute Javascript on any site I like by typing it in the navigation bar.So giving "permission" with Javascript to access other pages would be very easy to do if it was possible.

Link to comment
Share on other sites

I don't know specifically what you're trying to do, but you might be able to use a PHP proxy. Javascript would send an AJAX request to a PHP page which would send the request to the page in the other domain and get the response back, then PHP could send the response back to the first Javascript. If the sites just need to exchange data then that would work, but you wouldn't be able to execute a specific Javascript function on an external page.

Link to comment
Share on other sites

  • 1 month later...

"Contained in the main site" .. are you saying that you can't link to a script file on another domain from blogspot.com? Are you trying to embed an HTML or page or something and execute Javascript commands on that external HTML page, or are you just trying to link to a script file on another domain?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...