473,513 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

conditional url

60 New Member
hi,

i would like to know how i can evaluate the current url so that either javascript:history.go(-1)'or javascript:history.go(-2) is executed. I would like for the javascript:history.go(-2) to be executed if the url is suffixed with the "#top"... like http://localhost...#top. I currently have:

Expand|Select|Wrap|Line Numbers
  1. echo "<A HREF='javascript:javascript:history.go(-1)'>HOME</A><br><br>";
  2.  

thanks in advance,
geebee
Jan 21 '09 #1
22 2642
Dormilich
8,658 Recognized Expert Moderator Expert
test for the window.location.hash property. (MDC – window.location)
Jan 21 '09 #2
geraldjr30
60 New Member
now i have:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3.  
  4. <BODY>
  5.  
  6. <SCRIPT LANGUAGE="JavaScript">
  7.  
  8.  function showLoc()
  9.  {
  10.    var x = window.location;
  11.  
  12. if (x = "http://httplocalhost/checkurl.html")
  13. {
  14. document.write("<a href='http://www.microsoft.com'>go to microsoft</a>");
  15. }
  16. else
  17. {
  18. document.write "stay here"
  19. }
  20.  
  21.    var t = ['Property - Typeof - Value',
  22.             'window.location - ' + (typeof x) + ' - ' + x ];
  23.    for (var prop in x){
  24.      t.push(prop + ' - ' + (typeof x[prop]) + ' - ' +  (x[prop] || 'n/a'));
  25.    }
  26.    alert(t.join('\n'));
  27.  }
  28. </SCRIPT>
  29.  
  30.  
  31.  
  32. </html>
  33.  
but its not doing anything...



saying "error on page" at the bottom of the window.
Jan 21 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
firstly, window.location is an object, not a string. secondly, there's a syntax error in line 18 (missing brackets) and probably the wrong operator on line 12. thirdly, javascript should be served with a type declaration in the <script> tag.
Jan 21 '09 #4
geraldjr30
60 New Member
ok..

i figure it out.. here is my code... appearing at the bottom after the PHP code:
Expand|Select|Wrap|Line Numbers
  1. <SCRIPT LANGUAGE="JavaScript">
  2.  function showLoc()
  3.  {
  4.    var x = window.location;
  5. if (x == "http://localhost/checkurl.html")
  6. {
  7. document.write("<a href='http://www.microsoft.com'>go to microsoft</a>");
  8. }
  9. else
  10. {
  11. document.write ("stay here")
  12. }
  13.  
  14.  }
  15.  
  16. x=0;
  17. document.self.location.reload();
  18. </SCRIPT>
  19.  

the only problem now is i cant figure out how to get the document.write results after the results of my PHP are listed. i tried <BODY ONLOAD = ...> but that only lists the document.write output from the javascript.

thanks in advance,
geebee
Jan 21 '09 #5
Dormilich
8,658 Recognized Expert Moderator Expert
@geraldjr30
what PHP code?

just out of interest, do you ever enter the first statement in the if clause?
Jan 21 '09 #6
geraldjr30
60 New Member
yes, i entered the first line of the IF statement. but it only works if i have the <BODY ONLOAD = showLoc()..> and then my PHP output does not display. only the document.write output from the javascript function displays. i want the PHP results to display as a result of my PHP code (not posted here because it is irrelevant i think), and then the document.write from the javascript function to be displayed beneath that.

thanks in advance,
geebee
Jan 21 '09 #7
Dormilich
8,658 Recognized Expert Moderator Expert
@geraldjr30
obviously.... the output is defined in a function after all

@geraldjr30
then there is something wrong with your PHP code.
Jan 21 '09 #8
acoder
16,027 Recognized Expert Moderator MVP
@geraldjr30
document.write reopens the document for writing, so don't use it after the page has loaded. Either use DOM methods, set innerHTML of an element or use it during page load only.
Jan 21 '09 #9
geraldjr30
60 New Member
ok... i think im almost there..

i have..
Expand|Select|Wrap|Line Numbers
  1. <?php>
  2. ...
  3. ...
  4. ?>
  5.  
  6. <SCRIPT LANGUAGE="JavaScript">
  7. function showLoc()
  8.  {
  9.    var x = window.location;
  10. if (x == "http://localhost/REC.php?count=sunday&fac=des&SRG_GROUP=Charity")
  11. {
  12.  
  13. document.body.innerHTML += "<a href=\"http://www.AOL.com\">AOL</a>";
  14. }
  15. else
  16. {
  17. document.body.innerHTML += "<a href=\"http://www.msn.com\">MICROSOFT</a>";
  18. }
  19. }
  20. </SCRIPT>
  21.  
but neither AHREF is being shown on the page...

thanks in advance,
geebee
Jan 21 '09 #10
acoder
16,027 Recognized Expert Moderator MVP
Are you calling showLoc body onload?
Jan 21 '09 #11
geraldjr30
60 New Member
now i am calling it on BODY load.. but the MICROSOFT link is appearing. The url in the address bar is

http://localhost/REC.php?count=sunda..._GROUP=Charity

so it should be listing the AOL link instead... am i evaluating the current url wrong? once again my code is...

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT LANGUAGE="JavaScript">
  2. function showLoc()
  3.  {
  4.    var x = window.location;
  5. if (x == "http://localhost/REC.php?count=sunday&fac=DES&SRG_GROUP=Charity")
  6. {
  7.  
  8. document.body.innerHTML += "<a href=\"http://www.AOL.com\">AOL</a>";
  9. }
  10. else
  11. {
  12. document.body.innerHTML += "<a href=\"http://www.msn.com\">MICROSOFT</a>";
  13. }
  14. }
  15. </SCRIPT>
  16.  
thanks in advance,
geebee
Jan 22 '09 #12
Dormilich
8,658 Recognized Expert Moderator Expert
try this one:
Expand|Select|Wrap|Line Numbers
  1. if (x.href == "http://localhost/REC.php?count=sunday&fac=DES&SRG_GROUP=Charity")
Jan 22 '09 #13
geraldjr30
60 New Member
ok thanks... that works!!!! now all i need to figure out is to evaluate whether or not the url in the address bar is suffixed with "#top", as there may be any day followed by the word "count" in the url, and i would rather not have an if statement for ever day of the week. how would i amend this?

thanks in advance,
geebee
Jan 22 '09 #14
Dormilich
8,658 Recognized Expert Moderator Expert
@geraldjr30
I've told you about that problem already in post #4 (and #6)........
@geraldjr30
use window.location.hash (see post #2)

regards
Jan 22 '09 #15
geraldjr30
60 New Member
it works... but no matter how hard i try, i cant get the MICROSOFT or AOL link to appear at the top of the page... it appears off to the side of the PHP output...

Expand|Select|Wrap|Line Numbers
  1. <BODY onload="showLoc();">
  2.  
  3.  
  4. <SCRIPT LANGUAGE="JavaScript">
  5.    function showLoc() 
  6.  { 
  7.    var x = window.location.hash; 
  8. if (x == "#top") 
  9. {
  10.  
  11. document.body.innerHTML += "<a href=\"http://www.AOL.com\">AOL</a>";
  12. }
  13. else
  14. {
  15. document.body.innerHTML += "<a href=\"http://www.msn.com\">MICROSOFT</a>";
  16. }
  17. }
  18. </SCRIPT>
  19.  

thanks in advance,
geebee
Jan 22 '09 #16
Dormilich
8,658 Recognized Expert Moderator Expert
it will be appended at the end.... looks like it. to get it on the top either use DOM methods to include the links or a different styling.
Jan 22 '09 #17
geraldjr30
60 New Member
thanks...

how i get the page to refresh with the following:

Expand|Select|Wrap|Line Numbers
  1. echo "<td width = '100' height = '10'><br><a href='#top'>back to top</a></td>";
  2.  

thanks in advance,
geebee
Jan 22 '09 #18
Dormilich
8,658 Recognized Expert Moderator Expert
besides clicking on the link?
Jan 22 '09 #19
geraldjr30
60 New Member
i want it to refresh when you click on the #top link
Jan 22 '09 #20
Dormilich
8,658 Recognized Expert Moderator Expert
ah, try with the whole url. like href="localhost/this_page.htm#top".
Jan 22 '09 #21
geraldjr30
60 New Member
will this work even if the url parameters are changed? like the url for this page could change depending on the form values posted to it from the previous page.
Jan 22 '09 #22
Dormilich
8,658 Recognized Expert Moderator Expert
if you send the values via POST then you don't need to worry. you can get the URL in PHP via the $_SERVER variable (just check out phpinfo()). if I remember right it's $_SERVER['REQUEST_URI']. but others may do as well.
Jan 22 '09 #23

Sign in to post your reply or Sign up for a free account.

Similar topics

8
2263
by: neblackcat | last post by:
Would anyone like to comment on the following idea? I was just going to offer it as a new PEP until it was suggested that I post it here for comment & consideration against PEP 308. I'm far...
28
3414
by: Benjamin Niemann | last post by:
Hello, I've been just investigating IE conditional comments - hiding things from non-IE/Win browsers is easy, but I wanted to know, if it's possible to hide code from IE/Win browsers. I found...
3
5920
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
4
3115
by: Bradley | last post by:
I have an A2000 database in which I have a continuous form with a tick box. There is also a text box with a conditional format that is based on the expression , if it's true then change the...
1
4955
by: GGerard | last post by:
Hello Is there a way to use a variable in the Conditional Formatting of a Textbox? Example : I want the background of a textbox in a continuous form to change color when the value of...
7
2319
by: John Dolinka | last post by:
I have a project of several files with #defines to setup a conditional compile. I would like to put these #defines in a single file and change the conditional compile from this one file with the...
10
28599
by: John Smith | last post by:
After reading C# documentation the Conditional attribute seemed the way to go, but after inspecting the IL it seems those methods are still there and I imagine the CLR removes them. Using #if DEBUG...
8
5078
by: Olov Johansson | last post by:
I just found out that JavaScript 1.5 (I tested this with Firefox 1.0.7 and Konqueror 3.5) has support not only for standard function definitions, function expressions (lambdas) and Function...
8
8461
by: Typehigh | last post by:
I have many text fields with conditional formatting applied, specifically when the condition is "Field Has Focus". Without any events associated with the fields the conditional formatting works...
5
2891
by: paulo | last post by:
Can anyone please tell me how the C language interprets the following code: #include <stdio.h> int main(void) { int a = 1; int b = 10; int x = 3;
0
7157
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7521
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5682
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.