Link to home
Create AccountLog in
Avatar of yando18
yando18

asked on

Need help with URL parameter that loads a function.

Hey All,

Need help writing a script that fires a function based on url parameters. The function would trigger an overlay to open.

For example the url would be www.tester.com?firefunction


Any help would be much appreciated.
Avatar of plusone3055
plusone3055
Flag of United States of America image

Avatar of yando18
yando18

ASKER

That works with the hash tag applied however I need to use "?" since some search providers strip out the hash. Thoughts?
http://stackoverflow.com/questions/6076576/how-to-execute-a-js-function-based-on-url-hash-urlnameoffunction

window.onload = function(){     var hash = (window.location.hash).replace('#', '? ');     if (hash.length == 0) {         //no hash do something     }     else {         //else do something with hash     } }
window.onload = function()
{
    var hash = (window.location.hash).replace('#', '?');     if (hash.length == 0) {
        //no hash do something     }
    else {
         //else do something with hash     } }
Avatar of yando18

ASKER

Is there another way besides hash. I cant use it since it gets stripped from the url during a paid search.
Also the url parameters have to be more specific.

?test1

So if the url has ?test1 applied to then fire the function. Thanks for help.
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of yando18

ASKER

mplungjan:

That seems to have worked is there any way make it only look at the end of the url. By using href.substring(end) ?
Not sure what you mean. Show me a typical URL and a String to search for
Avatar of yando18

ASKER

#test varies for example might be

www.test.aspx#test?firefunction

or

www.test.aspx#tester?firefunction


...maybe could be solved with regular expressions.
My code will find ?firefunction anywhere. I do not recommend a ? AFTER a #
Avatar of yando18

ASKER

I see ok thanks alot for your help.