2014-01-09 98 views
1

我正在设计一个简单的ASPX页面,其中有两个div's。第一个div有静态内容。在第二个我想要的内容是动态的。我希望用户在查询字符串中提供URL,并且需要在我的第二个div中显示该URL。到目前为止,我已经做到了。从查询字符串获取网址并将其加载到div中

的Index.aspx:

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title>Frames Example</title> 
    <script type="text/javascript"> 
     function LoadQueryPage() { 
      var str = <%= new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(Request.QueryString["pagename"]) %> 

      $("#siteloader") 
      .html('<object data=' + str + '/>'); 
     } 
    </script> 
</head> 
<body> 
    <div style="min-height: inherit; height: 100px;"> 
     Farhan S. Mukadam 
    </div> 
    <div> 
    <object type="text/html" data="http://validator.w3.org/" width="800px" height="600px" style="overflow:auto;border:5px ridge blue"> 
    </object></div> 
</body> 
</html> 

但是,这是行不通的。有人可以请帮助。

+2

包括jQuery的'这不是working' ...什么是错误...? – NoobEditor

+0

它从Querystring中获取值。我不完全清楚。我从某处获得了这个JS代码。 –

+1

其中是'GetParameterValues'的执行方式 –

回答

1

尝试

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js"></script> 
<script> 
    $(function() { 
     var pagename = GetParameterValues('pagename'); 
     $('#siteloader').load(pagename); 
    }); //missing) here 
    function GetParameterValues(param) { 
     var regex = new RegExp('(\\?|&)' + param + '=(.*?)()(&|$)') 
     return location.href.match(regex)[2]; 
    } 
</script> 

你也没有在页面

+0

没有成功。我只能看到第一个div。第二格没有内容。 –

+0

@ FarhanMukadam在控制台中的任何其他错误 –

+0

@ FarhanMukadam看到更新 –

1
function GetRequestParameters(name) { 
    if (name = (new RegExp('[?&]' + encodeURIComponent(name) + '=([^&]*)')).exec(location.search)) 
     return decodeURIComponent(name[1]); 
} 
相关问题