最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

query string - Getting QueryString from Request or Javascript - Stack Overflow

programmeradmin1浏览0评论

In aspx I have a querystring - www.mysite/enter.aspx?dest=#. When I click "enter" I go to main.aspx. I want to get this "?dest=#" in main.aspx with a request.querystring or something in javascript. I need to use the querystring in javascript in main.aspx for another action.

Any ideas?

let me explain in detail - I have enter.aspx page that shall load with a querystring - www.mysite/enter.aspx?dest=#. Now when i click the Enter button on Enter.aspx page, it shall goto Main.aspx page. When main.aspx page loads i want to write small javascript in main.aspx that shall get the querystring from the previous enter.aspx page and give it an if condition. so if (request.querystring('dest=') > 0 window.open ('a1.jpg') this above code needs to be redesigned so it can work. how can i do this. i tried window.location.href.indexof('dest') , nothing happened.

In aspx I have a querystring - www.mysite./enter.aspx?dest=#. When I click "enter" I go to main.aspx. I want to get this "?dest=#" in main.aspx with a request.querystring or something in javascript. I need to use the querystring in javascript in main.aspx for another action.

Any ideas?

let me explain in detail - I have enter.aspx page that shall load with a querystring - www.mysite./enter.aspx?dest=#. Now when i click the Enter button on Enter.aspx page, it shall goto Main.aspx page. When main.aspx page loads i want to write small javascript in main.aspx that shall get the querystring from the previous enter.aspx page and give it an if condition. so if (request.querystring('dest=') > 0 window.open ('a1.jpg') this above code needs to be redesigned so it can work. how can i do this. i tried window.location.href.indexof('dest') , nothing happened.

Share Improve this question edited Jan 19, 2010 at 19:33 poikuu asked Jan 19, 2010 at 19:18 poikuupoikuu 251 silver badge2 bronze badges 1
  • 3 Please slow down and try to make your question much, much clearer. – Telemachus Commented Jan 19, 2010 at 19:20
Add a ment  | 

6 Answers 6

Reset to default 3
alert(window.location.search); // ?dest=#

This is a bit messy.. YUI has a simple method to get at the querystring response by Gavin Brock.

How do you get querystring using YUI 2?

To get the current address in javascript you could use window.location.href and test if it contains a given string:

<script type="text/javascript">
if (window.location.href.indexOf('dest=') > 0) {
    window.open('images/newyork.jpg','','') 
}
</script>

If you don't have to do this in Javascript, you can always grab the querystring in the codebehind of enter.aspx, then perform a Response.Redirect to main.aspx, appending on the querystring.

If you want to get the url from the previous page, you should use "document.referrer".

<script type="text/javascript">
if (document.referrer.indexOf('dest=') > 0) {
    window.open("a1.jpg");
}

Yes. You can read the querystring from JavaScript. Here are some links to get you started:

  • http://javascript.about./library/blqs1.htm
  • http://ilovethecode./Javascript/Javascript-Tutorials-How_To-Easy/Get_Query_String_Using_Javascript.shtml
  • Link
发布评论

评论列表(0)

  1. 暂无评论