Redirecting user depending on a uri query

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Redirecting user depending on a uri query

Post by Luke »

I am working in MIVA (a merchant/online store solution) and I can not get under the hood of their code, so I need to find a way to cheat it. What I need to do is redirect users to a specific page depending on a variable set in the URI, but since I can't get into the backend code, I need to find a way to do it client-side... any ideas?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Maybe if I used an iframe that calls a php script... how would I make an iframe invisible/unable to be seen by visitors?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

To answer your second post

Code: Select all

<iframe src="somepage" height="0" width="0" frameborder="0" style="display: none;"></iframe>
Although I believe just the display: none part will do the trick. ;)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

how would I make an iframe invisible/unable to be seen by visitors?

Code: Select all

<html>
<body>
  <style type='text/css'>
     iframe.hidden {
         float:left;
         margin-left:-100000;
     }
     /* or simply */
     /*
      iframe.hidden {
          display:hidden;
          height:1px;
      }
      */
     /* or */
     /*
      iframe.hidden {
           display:none;
      }
      */
  </style>
  <iframe id='hiddenFrame' name='hiddenFrame' class='hidden'></iframe>
</body>
</html>
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

ok... I have another question

in the iframe i called a php script which tests whether the $_GET variable is set and I set the $_GET variable (in the parent window). The iframe test says that it isn't set because the variable isn't being set in the iframe. How do I pass the query string from the URI to the iframe?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

<iframe src="somepage.php?<?php echo $_SERVER['QUERY_STRING']; ?>">
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

The problem with that is that the parent frame needs to be a standard html page... can't put php in the parent frame... :(

I don't think this iframe thing is going to work... it won't redirect the parent frame without the use of javascript, so I may as well just put the javascript on the parent frame... but I am lame in javascript.

Is there a way to redirect with javascript depending on the query string?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Just in case somebody comes to this thread with the same question... I solved the problem like this:

Code: Select all

<script language="javascript" type="text/javascript">
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  return false;
}
var cat_code = getQueryVariable("Category_Code");
if(cat_code == "AR"){
        window.location = "http://www.somedomain.com/mm5/merchant.mvc?Screen=ARTS&Category_Code=AR&Store_Code=T";
}
else if(cat_code == "SP"){
        window.location = "http://www.somedomain.com/mm5/merchant.mvc?Screen=SPTF&Category_Code=SP&Store_Code=T";
}
</script>
Post Reply