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.
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.
http://stackoverflow.com/questions/6076576/how-to-execute-a-js-function-based-on-url-hash-urlnameoffunction
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).rep lace('#', '? '); if (hash.length == 0) { //no hash do something } else { //else do something with hash } }
window.onload = function(){ var hash = (window.location.hash).rep
window.onload = function()
{
var hash = (window.location.hash).replace('#', '?'); if (hash.length == 0) {
//no hash do something }
else {
//else do something with hash } }
{
var hash = (window.location.hash).replace('#', '?'); if (hash.length == 0) {
//no hash do something }
else {
//else do something with hash } }
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.
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 :)
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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) ?
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
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.
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 #
ASKER
I see ok thanks alot for your help.