davefootball123 Posted March 4, 2013 Share Posted March 4, 2013 I have a link <a href="http://www.sowx.ca/eccast/eccast.php"> as well as a javascript function that gets latitude and longitude seen below. What I need to do is take the latitude longitude and have it set the link as <a href="http://www.sowx.ca/eccast/eccast.php?lat=+lat&lon=+lon> fron the javascript function. I was able to do this by setting the href with an id and changing the . href attribute with the id however It did not work in Firefox. I imagine I have to use onclick() or something along those lines. If someone could help me out with this that would be awesome. Thanks, Dave <script type="text/javascript"> if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(successFunction, errorFunction); } else { alert('Geolocation is required for this page,'); } function successFunction(position) { var lat = position.coords.latitude; var lon = position.coords.longitude; } function errorFunction(position) { alert('Error!'); } </script> Link to comment https://forums.phpfreaks.com/topic/275248-need-help-setting/ Share on other sites More sharing options...
requinix Posted March 4, 2013 Share Posted March 4, 2013 So what was the code you tried? I assume it went inside successFunction()? Link to comment https://forums.phpfreaks.com/topic/275248-need-help-setting/#findComment-1416593 Share on other sites More sharing options...
davefootball123 Posted March 5, 2013 Author Share Posted March 5, 2013 So what was the code you tried? I assume it went inside successFunction()? Yes it did for example I had the code seen below and my <a href had an id of "loc", worked ok in chrome and IE...just not firefox. document.getElementById("loc").href='eccast.php?lat='+lat+'&lon='+lon; Link to comment https://forums.phpfreaks.com/topic/275248-need-help-setting/#findComment-1416596 Share on other sites More sharing options...
requinix Posted March 5, 2013 Share Posted March 5, 2013 Any errors? Link to comment https://forums.phpfreaks.com/topic/275248-need-help-setting/#findComment-1416605 Share on other sites More sharing options...
davefootball123 Posted March 5, 2013 Author Share Posted March 5, 2013 Any errors? In FireFox...no just doesnt set the lat/lon Link to comment https://forums.phpfreaks.com/topic/275248-need-help-setting/#findComment-1416607 Share on other sites More sharing options...
teynon Posted March 5, 2013 Share Posted March 5, 2013 window.onerror = function(message, url, lineNumber) { alert(message + " | " + lineNumber + " | " + url); return true; }; Add the code above and / or look at your console. (Run it again afterwards.) Link to comment https://forums.phpfreaks.com/topic/275248-need-help-setting/#findComment-1416624 Share on other sites More sharing options...
davefootball123 Posted March 5, 2013 Author Share Posted March 5, 2013 window.onerror = function(message, url, lineNumber) { alert(message + " | " + lineNumber + " | " + url); return true; }; Add the code above and / or look at your console. (Run it again afterwards.) Thanks for your response. Surprisingly it doesn't return an error. I notice this. It works as it should in Chrome and in Internet Explorer, however I have to load the page and then do 1 refresh for it to work in Firefox. Odd. Any thoughts? Full code is posted below, minus the code you gave me above. <script type="text/javascript"> if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(successFunction, errorFunction); } else { alert('Geolocation is required for this page,'); } function successFunction(position) { var lat = position.coords.latitude; var lon = position.coords.longitude; document.getElementById("loc").href='http://www.sowx.ca/eccast/eccast.php?lat='+lat+'&lon='+lon; } function errorFunction(position) { alert('Error!'); } </script> <ul> <li class="current"><a href='http://www.sowx.ca'><span class="current">Warnings</span></a></li> <li><a href="http://www.sowx.ca/eccast/eccast.php" id="loc"><span>Local</span></a></li> </ul> Link to comment https://forums.phpfreaks.com/topic/275248-need-help-setting/#findComment-1416629 Share on other sites More sharing options...
teynon Posted March 5, 2013 Share Posted March 5, 2013 Just curious, do you still have to refresh it? Or just that one time? Link to comment https://forums.phpfreaks.com/topic/275248-need-help-setting/#findComment-1416631 Share on other sites More sharing options...
davefootball123 Posted March 5, 2013 Author Share Posted March 5, 2013 Just curious, do you still have to refresh it? Or just that one time? If I refresh once, I can go back and then click the link and it will work fine, however if I go to a new page then go back it fails to work agian. Link to comment https://forums.phpfreaks.com/topic/275248-need-help-setting/#findComment-1416632 Share on other sites More sharing options...
teynon Posted March 5, 2013 Share Posted March 5, 2013 Works fine for my firefox. Although it does annoyingly ask for permission every time. Link to comment https://forums.phpfreaks.com/topic/275248-need-help-setting/#findComment-1416634 Share on other sites More sharing options...
davefootball123 Posted March 5, 2013 Author Share Posted March 5, 2013 Works fine for my firefox. Although it does annoyingly ask for permission every time. I see, chrome only asks once and you're set. Same with IE. Do you have any recommendations on how I could fix this issue? Any other geolocation api's I should look into? Link to comment https://forums.phpfreaks.com/topic/275248-need-help-setting/#findComment-1416636 Share on other sites More sharing options...
teynon Posted March 5, 2013 Share Posted March 5, 2013 You could click the arrow and click "Always Share Location" Link to comment https://forums.phpfreaks.com/topic/275248-need-help-setting/#findComment-1416637 Share on other sites More sharing options...
davefootball123 Posted March 5, 2013 Author Share Posted March 5, 2013 You could click the arrow and click "Always Share Location" Always sharing location is fine. Just not sure how to have it so Firefox doesnt need a refresh in order to have the .href set properly. Link to comment https://forums.phpfreaks.com/topic/275248-need-help-setting/#findComment-1416638 Share on other sites More sharing options...
teynon Posted March 5, 2013 Share Posted March 5, 2013 Maybe there isn't enough fire in your fox. My firefox works just fine with that code. Link to comment https://forums.phpfreaks.com/topic/275248-need-help-setting/#findComment-1416639 Share on other sites More sharing options...
davefootball123 Posted March 5, 2013 Author Share Posted March 5, 2013 Maybe there isn't enough fire in your fox. My firefox works just fine with that code. Haha, maybe. What OS and version of FF are you using? Link to comment https://forums.phpfreaks.com/topic/275248-need-help-setting/#findComment-1416646 Share on other sites More sharing options...
teynon Posted March 5, 2013 Share Posted March 5, 2013 Windows 7 Ultimate and FF 18.0.2 Link to comment https://forums.phpfreaks.com/topic/275248-need-help-setting/#findComment-1416648 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.