Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check URL and add GET value as required

Status
Not open for further replies.

BlankCanvas

Technical User
Joined
Nov 12, 2002
Messages
5
Location
TH
Hi,

I have a simple frame buster script as follows:

<script language=&quot;JavaScript&quot;>
<!-- Hide from old browsers
if (self.parent.frames.length != 0){
self.parent.location=document.location;
}
// end hide -->
</script>

It works just great on my pages (which are PHP) but I would really like to know which sites are trying to load my pages in frames. Which I can log and monitor in PHP which I understand better then JavaScript.

What I would really like to do is find out if the &quot;document.location&quot; URL value contains a GET value of &quot;?username=johndoe&quot; for example and if so append the value of &quot;&FrameBusted=Yes&quot;. and if the URL does not contain any GET values add &quot;?FrameBusted=Yes&quot; as it would be the first get value and needs a ? over the &.

If someone can help me on this I would really appreciate it.

Thanks

Stephen
 
The location object has a property called .search which contains the portion of the URL after the question mark, if, for this page it would be [tt]SQID=618032&SPID=216&page=1[/tt]

All you would need to do is check to see if search was empty or had something in it, then append the appropriate version of FrameBusted.
Code:
<script language=&quot;JavaScript&quot;>
 <!-- Hide from old browsers
 if (self.parent.frames.length != 0){
  if(document.location.search != ''){
   //Already have something in search string
   //Append &FrameBusted=Yes
   self.parent.location=document.location + '&FrameBusted=Yes';
  }
  else{
   //Nothing in search string
   //Append ?FrameBusted=Yes
   self.parent.location=document.location + '?FrameBusted=Yes';
  }
 }
 // end hide -->
</script>
 
Just wanted to say a BIG thanks to you for this help, it looks so easy when you see a pro do the coding :-)

Thanks again, great modified script.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top