开发者

Cancel navigation on a frame?

Say I have a frameset with a frame where Google is loaded. I want to prevent Google from navigating any开发者_如何学JAVAwhere when the user click on a link or a button. Is this possible?


I don't think it's possible. The only way that comes into my mind is to use a simple Javascript code in the parent frameset to detect when the child frame containing Google Home Page has been reloaded because user pressed a link in it, and then force the child frame to reload again the Google Home Page. Something like:

<script type="text/javascript">
   var flag_1st_time_call = true;
   function ReloadGoogleHome()
   {
      if(!flag_1st_time_call)
      {
         document.getElementById('myframe').src = "http://www.google.com";
      /* I'm not sure you can get frame with document.getElementById (I'm 
         more confortbale with IFRAMEs) anyway I think you understood the example */
      }
      flag_1st_time_call = false;
   }
</script>

<frame src="http://www.google.com" id="myframe" onload="ReloadGoogleHome();"></frame>

This does not prevent user to click on links and display for a while the page where they navigated too, but suddenly they will be brought back to Google HOME PAGE.

Another possible solution (if you were using IFRAME in a page to show Google instead of a frameset) is to create a position aboslute div element in the parent page (the one that contains the IFRAME) with opacity and make it cover the IFRAME, in this way user won't be able to interact at all with the Google page displaied in the IFRAME.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜