Forum Moderators: open

Message Too Old, No Replies

Need to prevent multiple same HTTP queries.

         

JAB Creations

4:27 am on Oct 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Script support for non-AJAX capable browsers (Opera 8.01 in example) are creating URL havoc!
file.php?prompt=sitethemes?prompt=sitechatroom?prompt=sitechatroom

Here is an example of the functions associated with those HTTP queries...

function sitechatroomshow() {location.href = location.href + '?prompt=sitechatroom';}
function sitethemesshow() {location.href = location.href + '?prompt=sitethemes';}

How do I mode these functions to include the current URL without any attaching any already present HTTP queries?

- John

daveVk

7:39 am on Oct 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



location.href = location.href.split('?')[0] + '?prompt=sitechatroom';

Dabrowski

2:14 pm on Oct 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could also use a regex, which I prefer:

// Select everything before first '?' 
location.href = location.href.replace( /^(.*?)\?.*$/, "$1");

// Or, delete any text matching location.search
location.href = location.href.replace( new RegExp( location.search), "$1");

The location object has many useful properties, try this on one of your pages:

alert( location.protocol +"\n"+ location.host +"\n"+ location.pathname +"\n"+ location.search);

JAB Creations

8:17 pm on Oct 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks to both of you for your replies! :)

- John

nICEsHARE

1:04 pm on Oct 30, 2007 (gmt 0)

10+ Year Member



Great help. This is what I did the search, too.
Thx