evibesmusic
asked on
How can I get the address bar location and then plug it into this JavaScript?
Hello Experts,
I have not tried to inject PHP into JavaScript before but, I know it can be done. This should be simple but, it would not surprise me if it is not.
This is what my page location looks like:
http://www.littledogonit.com/test/ask.php?cat=Consumer%20Electronics&sub_cat=Cell
I want to find the 'cat' and 'sub_cat' from the current page and introduce these variables into the script. Can anyone offer any suggestion?
I have not tried to inject PHP into JavaScript before but, I know it can be done. This should be simple but, it would not surprise me if it is not.
This is what my page location looks like:
http://www.littledogonit.com/test/ask.php?cat=Consumer%20Electronics&sub_cat=Cell
I want to find the 'cat' and 'sub_cat' from the current page and introduce these variables into the script. Can anyone offer any suggestion?
<?
$sub_catname = $_GET['sub_cat'];
$catname = $_GET['cat'];
?>
<script language="Javascript">
if (top.location == self.location) {
top.location = '../ask.php?cat=<? $_GET['cat'] ?>&sub_cat=<? $_GET['sub_cat'] ?>'
}
//-->
</script>
I think you should replace & with & when setting the URL like that because it's in a JavaScript string.
ASKER
fibo:
Sorry but, it is not working. The script is a redirect if you could not tell...when the script redirects in takes me to: http://www.littledogonit.com/test/ask.php?cat=&sub_cat=
Therefore, I think that it is still not grabbing the 'cat' and 'sub_cat'.
Any other thoughts?
EVibesMusic
Sorry but, it is not working. The script is a redirect if you could not tell...when the script redirects in takes me to: http://www.littledogonit.com/test/ask.php?cat=&sub_cat=
Therefore, I think that it is still not grabbing the 'cat' and 'sub_cat'.
Any other thoughts?
EVibesMusic
ASKER
A little more info...the page that this script is going into is inside of a frame.
When I click on the tab to display this page, the page breaks out of this frame.
The purpose of this script is to redirect it to the correct page. Don't know if this helps?
When I click on the tab to display this page, the page breaks out of this frame.
The purpose of this script is to redirect it to the correct page. Don't know if this helps?
ASKER
rohypnol:
Took the & out of the javascript and it did not have any effect. Thanks.
EVM
Took the & out of the javascript and it did not have any effect. Thanks.
EVM
1 - Let's check what your script is getting, and add some session handling code.
<?php
session-start();
$sub_catname = trim (' ' . @$_GET['sub_cat']);
$catname = trim (' ' . @$_GET['cat']);
$debug = true; // easy to change
if ($debug) {
echo "Upon entry, cat is [$catname] and sub_cat is [$sub_catname]";
echo "and all the data that is passed is "; var_dump($_REQUEST) ; echo '*** <br>';
}
?>
2 - the fact that there is a frame is indeed important!
First, just a side-note: there are very few cases where using frames is a good idea; frame are not good vor human visitors (eg, you do not know on which page you are, you cannot bookmark, history is somewhat useless; o,n top of that the spiders of search engines are lost too, a bad idea for referencement); in most cases where people are using frames, they could drop them, specially if they are running php; in most other cases, using an IFRAME is a bettre idea, although iframes were supposed to become deprecated at some stage (inserting Google Maps should lead to revise this deprecation!).
<<When I click on the tab to display this page, the page breaks out of this frame.
The purpose of this script is to redirect it to the correct page. Don't know if this helps?>>
We need more clarification here.
- is ask.php generationg your frameset? what are the html and php pages used to render your page? ask.php page?
- where is your script running into this schema?
- is ask.php where you redirect a framed or non frames page?
<?php
session-start();
$sub_catname = trim (' ' . @$_GET['sub_cat']);
$catname = trim (' ' . @$_GET['cat']);
$debug = true; // easy to change
if ($debug) {
echo "Upon entry, cat is [$catname] and sub_cat is [$sub_catname]";
echo "and all the data that is passed is "; var_dump($_REQUEST) ; echo '*** <br>';
}
?>
2 - the fact that there is a frame is indeed important!
First, just a side-note: there are very few cases where using frames is a good idea; frame are not good vor human visitors (eg, you do not know on which page you are, you cannot bookmark, history is somewhat useless; o,n top of that the spiders of search engines are lost too, a bad idea for referencement); in most cases where people are using frames, they could drop them, specially if they are running php; in most other cases, using an IFRAME is a bettre idea, although iframes were supposed to become deprecated at some stage (inserting Google Maps should lead to revise this deprecation!).
<<When I click on the tab to display this page, the page breaks out of this frame.
The purpose of this script is to redirect it to the correct page. Don't know if this helps?>>
We need more clarification here.
- is ask.php generationg your frameset? what are the html and php pages used to render your page? ask.php page?
- where is your script running into this schema?
- is ask.php where you redirect a framed or non frames page?
ASKER
fibo:
Thank you very much for the concern on all levels. I have found so many Experts that are willing to help and I can't tell you how much you guys make a difference. Thanks.
>>1 - Let's check what your script is getting, and add some session handling code.
This is what the code produced:
Upon entry, cat is [] and sub_cat is []and all the data that is passed is array(4) { ["1217906436603"]=> string(0) "" ["BX"]=> string(22) "04d7ded49d5tj&b=3&s=uf" ["PHPSESSID"]=> string(32) "0446ebc8211de8e38b3930ded 49a7cfb" ["countrytabs"]=> string(1) "1" } ***
Thank you for your concern in regards to the use of frames...as it turns out they are not actual frames but, an AJAX element that produces an effect where you can click on each tab and another page of content comes up. Otherwise I don't use frames.
You can see them in action here:
http://www.littledogonit.com/test/ask.php?cat=Food&sub_cat=Professional%20Chef
...along with your error message.
>> is ask.php generationg your frameset? what are the html and php pages used to render your page? ask.php page?
Answer: Yes, kinda...Ask.php contains the AJAX element that is dynamically feeding several pages to to be displayed on ask.php.
>> - where is your script running into this schema?
This is the only place where the script runs into this schema. The page that keeps breaking-out is question-form.php and this page appears only on ask.php where it is being fed via AJAX.
>> is ask.php where you redirect a framed or non frames page?
If the page breaks out of the frame and then the browser is redirected using this script, the page appears inside of the AJAX element as needed.
NOTE: This error is happening in both IE and FF have not checked other browsers yet.
Thanks,
EVM
Thank you very much for the concern on all levels. I have found so many Experts that are willing to help and I can't tell you how much you guys make a difference. Thanks.
>>1 - Let's check what your script is getting, and add some session handling code.
This is what the code produced:
Upon entry, cat is [] and sub_cat is []and all the data that is passed is array(4) { ["1217906436603"]=> string(0) "" ["BX"]=> string(22) "04d7ded49d5tj&b=3&s=uf" ["PHPSESSID"]=> string(32) "0446ebc8211de8e38b3930ded
Thank you for your concern in regards to the use of frames...as it turns out they are not actual frames but, an AJAX element that produces an effect where you can click on each tab and another page of content comes up. Otherwise I don't use frames.
You can see them in action here:
http://www.littledogonit.com/test/ask.php?cat=Food&sub_cat=Professional%20Chef
...along with your error message.
>> is ask.php generationg your frameset? what are the html and php pages used to render your page? ask.php page?
Answer: Yes, kinda...Ask.php contains the AJAX element that is dynamically feeding several pages to to be displayed on ask.php.
>> - where is your script running into this schema?
This is the only place where the script runs into this schema. The page that keeps breaking-out is question-form.php and this page appears only on ask.php where it is being fed via AJAX.
>> is ask.php where you redirect a framed or non frames page?
If the page breaks out of the frame and then the browser is redirected using this script, the page appears inside of the AJAX element as needed.
NOTE: This error is happening in both IE and FF have not checked other browsers yet.
Thanks,
EVM
1 - In the example given, the page is called without any element in the URL, therefore the GET values are empty and if the javascript is generated with empty values for cat and sub_cat this matches the expected behaviour.
2 - On the contrary, calling the page with values in the URL, such as the URL you are giving, does generate javascript with values in cat and sub_cat.
Ways too much in fact, since all the javascript on the right side in the "links box" do have the same value for cat and sub_cat.
The values on this "links box" should be generated using not the "variable" elements coming from some GET value, but more "stable" values coming either from some database info or from "constant" values, eg a php array with constant values.
3 - FYI: Not sure this is linked, but I am now using FireFox to display your pages, since I have been 3 times reading them in IE7 , then having IE7 crash (and also crashing the answers I had prepared for your question)... the crash is NOT immediate, I can switch to another IE tab but then IE freezes.
Again: I did not take the time to check if this is really related.
I notice that in some parts of the javascript code you are treating differently IE7... maybe the result is not on the par with expected behaviour.
2 - On the contrary, calling the page with values in the URL, such as the URL you are giving, does generate javascript with values in cat and sub_cat.
Ways too much in fact, since all the javascript on the right side in the "links box" do have the same value for cat and sub_cat.
The values on this "links box" should be generated using not the "variable" elements coming from some GET value, but more "stable" values coming either from some database info or from "constant" values, eg a php array with constant values.
3 - FYI: Not sure this is linked, but I am now using FireFox to display your pages, since I have been 3 times reading them in IE7 , then having IE7 crash (and also crashing the answers I had prepared for your question)... the crash is NOT immediate, I can switch to another IE tab but then IE freezes.
Again: I did not take the time to check if this is really related.
I notice that in some parts of the javascript code you are treating differently IE7... maybe the result is not on the par with expected behaviour.
ASKER
fibo:
Interesting...I haven't seen any browser lock up as a result of trying to view the ask.php page or any of the content that the AJAX element serves up.
I have noticed though that the problem does not appear to be an issue in FF 1.0, 2.0, or 3.0 just IE.
To be honest with you I don't know where in my code I treat IE differently...can you point this out. Not trying to come off as unaware of my code but, I have not purposely done this. It may have been there in a code snippet that was picked up on the web somewhere.
Thanks,
EVibesMusic
Interesting...I haven't seen any browser lock up as a result of trying to view the ask.php page or any of the content that the AJAX element serves up.
I have noticed though that the problem does not appear to be an issue in FF 1.0, 2.0, or 3.0 just IE.
To be honest with you I don't know where in my code I treat IE differently...can you point this out. Not trying to come off as unaware of my code but, I have not purposely done this. It may have been there in a code snippet that was picked up on the web somewhere.
Thanks,
EVibesMusic
According to Firefox, you have in the script http://www.littledogonit.com/test/ajaxtabs/ajaxtabs.js
the piece of code below, which I have not examined more than superficially since it is quite huge. No idea if this create a problem or not.
ddajaxtabs.connect=functio n(pageurl, tabinstance){
var page_request = false
var bustcacheparameter=""
*** if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
try {
page_request = new ActiveXObject("Msxml2.XMLH TTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.X MLHTTP")
}
catch (e){}
the piece of code below, which I have not examined more than superficially since it is quite huge. No idea if this create a problem or not.
ddajaxtabs.connect=functio
var page_request = false
var bustcacheparameter=""
*** if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
try {
page_request = new ActiveXObject("Msxml2.XMLH
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.X
}
catch (e){}
ASKER
I got this code from DynamicDrive.com so I have no idea how it works I just took it and ran with it.
Don't have any idea how to deal with the code you pointed out above...
Hmmmm....
EVM
Don't have any idea how to deal with the code you pointed out above...
Hmmmm....
EVM
OK. Let's switch back to the initial problem.
a - when you call the page with some calues for cat and sub_cat, do they display correctly in the debug display?
Are they transferred correctly as arguments to the javascript-handled URL?
b - have you started digging the logic which puts these erguments in all URLs?
a - when you call the page with some calues for cat and sub_cat, do they display correctly in the debug display?
Are they transferred correctly as arguments to the javascript-handled URL?
b - have you started digging the logic which puts these erguments in all URLs?
ASKER
>> a - when you call the page with some calues for cat and sub_cat, do they display correctly in the debug display? Are they transferred correctly as arguments to the javascript-handled URL?
This is what the debug code produced: Upon entry, cat is [] and sub_cat is []and all the data that is passed is array(4) { ["1217906436603"]=> string(0) "" ["BX"]=> string(22) "04d7ded49d5tj&b=3&s=uf" ["PHPSESSID"]=> string(32) "0446ebc8211de8e38b3930ded 49a7cfb" ["countrytabs"]=> string(1) "1" } ***
As you can see. the cat and sub_cat are [ ] indicating that the value is not being pulled. There fore it has no way of being transfered to the JavaScript.
My hunch as to why it is not working is due to the fact that when you click on the tab, the page that is supposed to remain in the frame, opens in a new window and then the script to get the values of the cat & sub_cat happen. Thus we have no results because when the page opens in a new browser the address contains no cat or sub_cat.
I think their is a problem with the ask.php page specifically becuase I have the same tab script on this page: http://www.littledogonit.com/test and the tabs function correctly. I am going to poke around in this direction to see if I can find the issue.
Thanks,
EVibesMusic
This is what the debug code produced: Upon entry, cat is [] and sub_cat is []and all the data that is passed is array(4) { ["1217906436603"]=> string(0) "" ["BX"]=> string(22) "04d7ded49d5tj&b=3&s=uf" ["PHPSESSID"]=> string(32) "0446ebc8211de8e38b3930ded
As you can see. the cat and sub_cat are [ ] indicating that the value is not being pulled. There fore it has no way of being transfered to the JavaScript.
My hunch as to why it is not working is due to the fact that when you click on the tab, the page that is supposed to remain in the frame, opens in a new window and then the script to get the values of the cat & sub_cat happen. Thus we have no results because when the page opens in a new browser the address contains no cat or sub_cat.
I think their is a problem with the ask.php page specifically becuase I have the same tab script on this page: http://www.littledogonit.com/test and the tabs function correctly. I am going to poke around in this direction to see if I can find the issue.
Thanks,
EVibesMusic
What if you call ask.php?cat=xxxx&sub_cat=y yyy
a - what does the debug display? what is transferred to html code / javascript?
<<My hunch as to why it is not working is due to the fact that when you click on the tab, the page that is supposed to remain in the frame, opens in a new window and then the script to get the values of the cat & sub_cat happen. Thus we have no results because when the page opens in a new browser the address contains no cat or sub_cat.>>
b - Just to be sure I understand:
1 - you have a container php page, with a "contained" php page in an iframe
2 - The container loads and uses some GET values to load/ display; it also displays the iframe using these values (more precisely the problem is that it should but does not).
3 - when you display the GET value for the contained / iframe, they are empty while they should have cat & sub_cat values.
- Is that correct?
- The current /test/ pages have no iframe.
- Is the GET data received correctly by the container? what does the debug display? how does it hand data to the contained? can you post your php code for this part?
- Do you display the GET values both in container and containee?
a - what does the debug display? what is transferred to html code / javascript?
<<My hunch as to why it is not working is due to the fact that when you click on the tab, the page that is supposed to remain in the frame, opens in a new window and then the script to get the values of the cat & sub_cat happen. Thus we have no results because when the page opens in a new browser the address contains no cat or sub_cat.>>
b - Just to be sure I understand:
1 - you have a container php page, with a "contained" php page in an iframe
2 - The container loads and uses some GET values to load/ display; it also displays the iframe using these values (more precisely the problem is that it should but does not).
3 - when you display the GET value for the contained / iframe, they are empty while they should have cat & sub_cat values.
- Is that correct?
- The current /test/ pages have no iframe.
- Is the GET data received correctly by the container? what does the debug display? how does it hand data to the contained? can you post your php code for this part?
- Do you display the GET values both in container and containee?
ASKER
fibo:
The problem was fixed with another solution. Thanks for your attempt to help me. I appreciate your time.
EVibesMusic.com
The problem was fixed with another solution. Thanks for your attempt to help me. I appreciate your time.
EVibesMusic.com
Please post your solution to the question, so that the knowledge base gains from the efforts.
You asked a question and we all worked very hard to bring you to a solution.
You asked a question and we all worked very hard to bring you to a solution.
ASKER
fibo...
The solution to the question at hand was not related to any of the suggested solutions above. Without going through each line of code, I created the page again starting from a new Dreamweaver Template that I have created and the page functioned as needed.
So, in essence...I have no answer, I just know that the problem is fixed and my page functions the way it was intended.
Thank you for your help...If I had a solution to offer I would definitely post it here. My only guess is that their was a error in the coding syntax used on the page in question.
EVibesMusic
The solution to the question at hand was not related to any of the suggested solutions above. Without going through each line of code, I created the page again starting from a new Dreamweaver Template that I have created and the page functioned as needed.
So, in essence...I have no answer, I just know that the problem is fixed and my page functions the way it was intended.
Thank you for your help...If I had a solution to offer I would definitely post it here. My only guess is that their was a error in the coding syntax used on the page in question.
EVibesMusic
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
OK for delete
VM, thx for your intervenition
VM, thx for your intervenition
$sub_catname = trim (' ' . @$_GET['sub_cat']);
$catname = trim (' ' . @$_GET['cat']);
?>
<script language="Javascript">
if (top.location == self.location) {
top.location = '../ask.php?cat=<?php echo $catname; ?>&sub_cat=<?php echo $sub_catname; ?>';
}
//-->
</script>