dongshan7708 2011-10-02 10:07
浏览 25
已采纳

有没有办法改变网址是iframe?

I want to show a page of my website within iframe in another page. I mean you can see helper.html while you are navigation main.php. but I want to change some links in helper.html regarding to some conditions set in main.php.

The regular solution is to get content of helper.html and process it in main.php, then echo it. But it is server side, I want this process to be client side.

Is that possible with JavaScript?

  • 写回答

4条回答 默认 最新

  • doubi3929 2011-10-02 11:01
    关注

    If those files are on different domains but you have a full control of them, then use the following solution:

    • In the main page call an iframe with GET parameters. For instance:

      <iframe src="foo.html?parameter=value" width="400" height="500"></iframe>
      
    • In an iframe parse GET parameters using Javascript and show an appropriate content:

      // get the current URL
      var url = window.location.toString();
      //get the parameters
      url.match(/\?(.+)$/);
      var params = RegExp.$1;
      // split up the query string and store in an
      // associative array
      var params = params.split("&");
      var queryStringList = {};
      
      for(var i=0;i<params.length;i++)
      {
          var tmp = params[i].split("=");
          queryStringList[tmp[0]] = unescape(tmp[1]);
      }
      
      // print all querystring in key value pairs
      for(var i in queryStringList)
          document.write(i+" = "+queryStringList[i]+"<br/>");
      

      Source: http://www.go4expert.com/forums/showthread.php?t=2163

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料