This is what I am trying to accomplish:
location.replace('http://localhost:8888/test/index.php?site=' + document.URL);
So I need the current URL to be send as a string of the site variable. Though the document.URL is not working, is there a way to get that working?
The idea is when I go to index.php the ‘site’ is inserted into a database. I would like the above link to work as a bookmarklet, (second part of the question) is there a way to execute that code but to still remain in the same page?
Basically if I am at google.com and click on the bookmarklet to execute the code above, Is there a way to remain at google.com but for the ..index.php to run in the background
At the moment I really need help with the first part of the question – but maybe you have any tips on how to achieve the second part?
encodeURIComponent(location.href), instead ofdocument.URL*
srcproperty of it.(new Image).src = urlwindow.open(url)(may be blocked, hinders the user)target=__, where__can be_blankor a frame name.[1] This method does not work across different domains. See also: MDN: Using XMLHttpRequest.
Another method (allows passing feedback from the server, in the form of JavaScript code).
Using Image:
EDIT alert + auto close
As requested in the comments, a pure JS alert which automatically closes after a certain time has elapsed. I’ve kept the function simple, for educative purposes. If you’re lazy, JQuery is also an option, although it’s overkill to include a whole framework for automatically hiding an “alert” box