问题
There are employees that will visit the external site to see a link to an internally hosted site. We only want the link to show if they have VPN'd into the network.
How, with JavaScript, can I test the availability of something that isn't online externally.
I have attempted to use a .JS file but it can get cached and seem available when it really isn't. Same with an image.
Maybe JSONP with MockJax to avoid cross-site scripting errors?
回答1:
On the intranet site make a JS file that will either embed the links or change them from display: none
to display: block
(or whatever display). On the page itself simply create a reference to that script and append the current date time to the end to avoid caching from the server.
Test case (this assumes you have localhost set up, but you can change it to be whatever intranet location):
Go here and the text won't be displayed.
Set up a file called test.js under localhost
with the contents
$(function(){
$('#test').show();
});
refresh the page and it will display the DIV's contents.
来源:https://stackoverflow.com/questions/13462925/how-to-test-if-an-employee-is-connected-via-vpn-with-client-side-javascript