what does this code do?
( i'm trying to build a web app analytics system, it must send javascript variables too php and then, php add variables to database ...
its a sample code that do this procces. I would like to "know that this code how sends javascript variables to php?" )
(function() {var no=0;var rand=Math.round(Math.random()*50000);var ref = escape(document.referrer) ; var u=(("https:" == document.location.protocol) ? "https" : "http") + "://analyticstest.com/rx/?xmain2/statsave/9101/50d77b1jkfd24c5db5ef36b22ed8a";
u = u + "&height=" + screen.height + '&width=' + screen.width +'&now=12552222091&phprand=56bf3sdkjnf220912528&rand='+rand+ '&title=1' ;
u = u + "&ref="+ref;
document.write ("<iframe scrolling=no frameborder=0 allowtransparency='true' src='"+u+"' border=0 width='0' height='0' style=' display:none;visibility:hidden'></iframe>");
Related
This is my script and it's being placed in the header internally on the html document:
<script type="text/javascript">
(function l(d){
var site = '6708', page = 'blahblah', s, er = d.createElement('script');
er.type = 'text/javascript';
er.async = true;
er.src = '//randomsite.com/?site=' + site + '&page=' + page; // **
s = d.getElementsByTagName('script')[0];
s.parentNode.insertBefore(er, s);
})(document);
</script>
and for some reason in Chrome when I check the console it shows up as
+ site + '&page='
instead of
+ site + '&page=' + page;
Edit
So the error disappeared after clearing up console and browser settings. But now a new error has shown up, and I'm not sure what this means
I'm at a loss as to why that is.
You should be getting Uncaught SyntaxError: Unexpected token * with the ** before site and after page. How have you embedded it in the html? this seemed to work fine for me:
<html>
<head>
</head>
<body>
<script type="text/javascript">
(function l(d){
var site = '6708', page = 'blahblah', s, er = d.createElement('script');
er.type = 'text/javascript';
er.async = true;
er.src = '//randomsite.com/?site=' + site + '&page=' + page;
s = d.getElementsByTagName('script')[0];
s.parentNode.insertBefore(er, s);
})(document);
</script>
</body>
</html>
Most likely you have an ad blocker installed in your browser. Disable it and try again. ;-)
I am having trouble getting css/js to show up on a Webview.
Here is what I am doing:
initializing the webview and engine
WebView browser = new WebView();
WebEngine webEngine = browser.getEngine();
webEngine.setJavaScriptEnabled(true);
This is where I load html content:
htmlViewImgBtn.addEventHandler(MouseEvent.MOUSE_CLICKED,
new EventHandler<MouseEven
#Override
public void handle(MouseEvent event){
if (counter == 0){
contentContainer.getChildren().addAll(browser);
webEngine.loadContent(export.getHTML(note));
//browser.getEngine().load("http://stackoverflow.com/questions/34554583/cant-load-css-js-on-javafx-webview");
contentContainer.getChildren().remove(noteContent);
counter = 1;
}
else {
contentContainer.getChildren().remove(browser);
contentContainer.getChildren().addAll(noteContent);
counter = 0;
}
}
});
Note: The commented code works when loading a website onto the webview, no issues. But Still does not work for the content I am loading.
The content (HTML) that is loaded looks looks like this:
<link href="prism.css" rel="stylesheet" type="text/css" />
<script src="prism.js" type="text/javascript"></script>
<pre><code class="language-java">System.out.println("Hello");
</code></pre>
Also, the css and js files are in the same directory as the java file
I can confirm that the html works by loading it on a web browser, What am I missing?
Blockquote
I was able to get it working by modifying the html as such:
"<link href=\"" + getClass().getResource("./prism.css") + "\"" + " rel=\"stylesheet\"" + " type=\"text/css\"" + " />\n" +
"<script src=\"" + getClass().getResource("./prism.js") + "\"" + " type=\"text/javascript\"" + "></script>\n" +
(rest of html);
You can use ResourceLoader to load HTML, js and css which are located in the same directory as the Java class.
URL url = getClass().getResource("index.html");
webEngine.load(url.toExternalForm());
Like the title says I'm trying to add a javascript tag into a innerHTML.
I have a combobox and depending on which value is selected it should load a script into a div
the script looks like this:
<script type="text/javascript">
_cashieProductID=292016;
document.write(unescape("%3Cscript src='" +
('https:' == document.location.protocol ? 'https://' : 'http://') +
"somelink.js'
type='text/javascript'%3E%3C/script%3E"));
</script>
when I put this into my script it shows all kind of text on my page that is part of the combobox script. So I hope someone can help me how to insert this code into my script so it will show the content that gets loaded with the code given above.
HTML
<select id="product" onchange="validate()">
function validate()
{
pName = document.getElementById('product');
var value = pName.options[pName.selectedIndex].value;
if(value == "4OFC")
loadJs(detail,"myjsSrc");
else if(/*some conditon*/)
{
// use this ladder to change the script address based on value of select box
}
else{
}
}
function loadJs(targetDiv,source)
{
var ele = document.getElementById(targetDiv);
if(ele)
{
var scr = document.createElement('script');
scr.type = 'text/javascript';
scr.src = source;
ele.appendChild(scr);
}
}
Just try the actual string in document.write, like this:
document.write("<script src='" + ('https:' == document.location.protocol ? 'https://' : 'http://') + "somelink.js' type='text/javascript'></script>");
I use this simple script:
<script type="text/javascript">
var _mytrack = _mytrack || [];
_mytrack.push(['_setType', 'SOMETYPE']);
_mytrack.push(['_setEmail', 'john#johndoe.com']);
(function() {
var mytrack = document.createElement('script');
_mytrack.type = 'text/javascript';
_mytrack.async = true;
mytrack.src = ('https:' == document.location.protocol ? 'https://www' : 'http://www') + '.mytrack.net/tracker.tell.php?i='+_mytrack;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(mytrack, s);
})();
</script>
My PHP script (tracker.tell.php) looks like this:
header("content-type: application/javascript");
echo "alert('".$_SERVER['REMOTE_ADDR']."');";
Now the question is related to the $_SERVER['REMOTE_ADDR'] because this gives (in an JS alert) the IP of the SERVER and not of the CLIENT.
$_SERVER['REMOTE_ADDR'] does give you the IP address of the remote user. But if you are using a proxy or load balancer, you should use $_SERVER['HTTP_X_FORWARDED_FOR']
If users can reach your server directly or through a proxy then just use an if statement
$remote_ip = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']);
then pass the variable to JS.
I'm currently using Mixpanel on my site. For some reasons they go down from time to time and that disables my site from loading.
Is there a way I can make the load async or some other idea where it doesn't bring down my site when they have downtime?
Here's the code:
<script>
var mp_protocol = (("https:" == document.location.protocol) ? "https://" : "http://");
document.write(unescape("%3Cscript src='" + mp_protocol + "api.mixpanel.com/site_media/js/api/mixpanel.js' type='text/javascript'%3E%3C/script%3E"));
</script>
Thanks
Do not document.write it to the page, append it.
<script>
$( function(){
var mp_protocol = (("https:" == document.location.protocol) ? "https://" : "http://");
jQuery.getScript(unescape(mp_protocol + "api.mixpanel.com/site_media/js/api/mixpanel.js"));
});
</script>