We help IT Professionals succeed at work.

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.
Comment
Watch Question

Author

Commented:
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     } }

Author

Commented:
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.
np :)
IT Expert
CERTIFIED EXPERT
Top Expert 2009
Commented:

window.onload = function() { 
 if (location.search && location.search == "?firefunction") firefunction()
}

Open in new window

Author

Commented:
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) ?
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
Not sure what you mean. Show me a typical URL and a String to search for

Author

Commented:
#test varies for example might be

www.test.aspx#test?firefunction

or

www.test.aspx#tester?firefunction


...maybe could be solved with regular expressions.
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
My code will find ?firefunction anywhere. I do not recommend a ? AFTER a #

Author

Commented:
I see ok thanks alot for your help.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.