How read external iframe via PHP or JavaScript - javascript

I want to track my package sent via the local post service: http://tandt.posta.sk/en.
With the tracking information, for example, RF166699170SK, I can locate the package.
but when I want to read it via PHP for example curl_setopt, via file_get_contents, or another method, I read only HTML code but in output missing text for example "Item posted at post office Dlhé Pole" which I can see on page.
because this page use iframe with some private method
http://www.posta.sk/en/sps-embed#tnt?q=RF166699170SK
but when I try to read this page (iframe), output missing information about package for example "Item posted at post office Dlhé Pole".
Output:
<!DOCTYPE html>
<html class="embed">
<head>
<link href="/sps/style.css?1450227250" media="screen,print" rel="stylesheet" type="text/css" />
<link href="/sps/print.css?1445466449" media="print" rel="stylesheet" type="text/css" />
<title>Slovenská pošta</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="google" value="notranslate">
<script type="text/javascript">CONFIG={"api":"http://api.posta.sk/private","tntShare":{"en":"http://tandt.posta.sk/en/items/{number}","sk":"http://tandt.posta.sk/zasielky/{number}"},"lang":"sk","home":"http://www.posta.sk","embed":true}</script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
<script src="/sps/script.js?1457665771" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
//<![CDATA[
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
//]]>
</script><script type="text/javascript">
//<![CDATA[
try {
var pageTracker = _gat._getTracker("UA-9600731-1");
pageTracker._setDomainName("posta.sk");
pageTracker._initData();
pageTracker._trackPageview();
} catch(err) {}
//]]>
</script>
</body>
</html>
Is it possible to read about this parcel via PHP or JavaScript?

If you inspect network connection of the page you linked you can see that there some data is loaded via JSON request. In your example data is requested from http://api.posta.sk/private/search?q=RF166699170SK&m=tnt
Maybe it would be the easiest way to get data direct from this API instead of trying to parse the result. The key is the same. You can convert the response in php like this:
<?php
$packageKey = 'RF166699170SK';
$data = json_decode('http://api.posta.sk/private/search?q='.$packageKey.'&m=tnt', TRUE);
?>
But I don't know if it's allowed by your postal service. You should ask if it's prohibited to do that.

There is an open API available for package tracking. Here you will find more information and documentation: https://www.posta.sk/informacie/api-dokumentacia
Example query: http://api.posta.sk/tracking?l=en&p=1&q=RF166699170SK

Related

How to use Mathquill on my website

I'm having problems in using mathquill on my website.
I'm new to this.
I'm stuck in this part
<link rel="stylesheet" type="text/css" href="/path/to/mathquill.css">`
<script src="/path/to/mathquill.min.js"></script>
I dont know what to put on the hrefs because I'm not seeing those files from mathquill file i got from github..
i downloaded the latest mathquill files and its inside htdocs(xampp) or www(wamp) together with my index.php.
Do i have to place my index.php inside mqthquill-0.10.1 folder?
Here is my
<link rel="stylesheet" href="/path/to/mathquill.css"/>
<script src="jquery-3.2.1.min.js"></script>
<script src="/path/to/mathquill.js"></script>
I appreciate if someone could give me the steps on how to use mathquill.
thanks in advance
Option 1
You can either download the mathquill.css and mathquill.js files from github and use them from your directory.
If you have your folder (directory) structure as below:
appFolder
.. scripts
.... mathquill.js
.... index.js
.. css
.... mathquill.css
myPage.html
Here's how you would reference the CSS and JS files:
<link rel="stylesheet" type="text/css" href="/css/mathquill.css">`
<script src="/scripts/mathquill.min.js"></script>
An easy way to check if your paths are correct is to put the entire URL in the browser's address bar. For example, if you are browsing the page as:
www.mydomain.com/mypage.html
The links to css and js files in the example folder structure I mentioned above would be:
www.mydomain.com/scripts/mathquill.js
www.mydomain.com/css/mathquill.css
Option 2
You could use the CDN to get the JS and CSS files on your page. Just copy the below two lines on to your html page, and you are ready to go.
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/mathquill/0.10.1/mathquill.min.css">`
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathquill/0.10.1/mathquill.min.js" type="text/javascript"></script>
<!-- COPY AND PAST THIS CODE HTML IN SOME EDITOR FOR BETTER VISUALIZATION, AFTER RUN-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Run Mathquill</title>
<!-- YOU NEED mathquill.css , jquery and mathquill.js SEARCH AND PICK IT SOMEWHERE, SEARCH ON THE WEB IF THIS DOWN NOT RUN-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mathquill/0.10.1/mathquill.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathquill/0.10.1/mathquill.js"></script>
<!-- INFORM THE LATEST AVERSION INTERFACE WITH THIS CODE -->
<script>
var MQ = MathQuill.getInterface(2);
</script>
</head>
<body>
<!--EXAMPLE COMMON TEXT TRANSFORMED WITH MATHQUILL -->
<p>Solve <span id="problem">f(x) = ax^2 + bx + c + = 0</span>.</p>
<script>
var problemSpan = document.getElementById('problem');
MQ.StaticMath(problemSpan);
</script>
<!-- EXAMPLE TO CREATE AN EDITABLE MATH FIELD -->
<p><span id="answer">x=</span></p>
<script>
var answerSpan = document.getElementById('answer');
var answerMathField = MQ.MathField(answerSpan, {
handlers: {
edit: function() {
var enteredMath = answerMathField.latex(); // Get entered math in LaTeX format
checkAnswer(enteredMath);
}
}
});
</script>
</body>
</html>

Access JSP variable in javascript

How do I pass the JSP variable to javascript function in external file?
I have the following set up
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="js/jquery/jquery-2.1.1.js"></script>
<script type="text/javascript" src="js/jquery/ui/jquery-ui.js"></script>
<script type="text/javascript" src="js/date/moment.js"></script>
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript" charset="utf-8" src="js/d3.js"></script>
<script type="text/javascript" src="js/myScript.js" ></script>
<link href="js/jquery/ui/jquery-ui.css" rel="stylesheet" />
<link href="js/jquery/ui/jquery-ui.theme.css" rel="stylesheet" />
<link href="css/myCSS.css" rel="stylesheet" />
<title>My Title</title>
</head>
<body>
<div id="myDIV">
<c:set var="myVar" value="${myInVar}" />
<script>runMyScript();</script>
</div>
</body>
</html>
Now inside my javascript, I try to access the jsp variable but neither of the two ways I found online works:
var javaScriptVar = '${myVar}';
var javaScriptVar2 = "<%=myVar%>";
Instead of the actual value of the jsp variables, I get the strings.
I read in this answer: Passing variable from JSP to Javascript which suggest to declare the variables before I include the javascript file, but I can't figure out how to do that.
If I put them in the header, they are not resolved because they come from a backend request.
If I don't include the script in the header and add src attribute to the script section before making the call, the method is never executed.
Totally confused here.
Your JavaScript is inside a .js file. The server will (exceptional circumstances aside) treat that as a static file. It will just serve it up to the client without processing.
If you want to run JSP code (such as <%=myVar%>) then put it in a JSP file.

Generating HTML <BASE> tag in JavaScript. Strange effects

I am having some inconsistencies regarding generating the HTML BASE tag in javaScript.
I have a global script of which the relevant parts are below. Every page in my site points to this script relatively. Then in the head section I call the following: generateBase();.
This appears to work well. All my CSS Twitter bootstrap files appear to do their job, the page renders and I've had no complaints from users. Looking at the logs on our server, and the developer console in chrome the it would seem that all links to JavaScript or CSS files are incorrectly relatively addressed.
Below is my header which calls generateBase() in settings.js. Below this is the important bits of settings.js.
Whilst I do not want to give the actual URL away, a flavor of the problem is below. I am expecting http://somewebsite.com/~mysite/js/bootstrap.js as the address for the bootstrap.js file. Howeever chrome reports that it is looking for http://somewebsite.com/~mysite/subfolder/subdir/js/bootstrap.js and gives a 403 even though the generateBase() call points to http://somewebsite.com/~mysite/. What I need is regardless of where each page of my site is located for them to be able to point to the required CSS and Javascripts that app pages need. I want the ability move a page without having to update all the URLS inside it.
Below is the head:
<head>
<script type="text/javascript" src="../../js/settings.js"></script>
<script type="text/javascript">generateBase();</script>
<meta charset="utf-8"></meta>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/bootstrapPurple.css" rel="stylesheet">
<link href="css/bootstrap-responsive.css" rel="stylesheet">
<link href="css/carousel-custom.css" rel="stylesheet">
<link href="css/pageStyle.css" rel="stylesheet">
<script src="js/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="js/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>
<script src="js/bootstrap.js" type="text/javascript"></script>
<script type="text/javascript" src="js/equalise.js"></script>
</head>
Settings.js Below:
var baseTestURL = "http://localhost/mySite/";//test local
var baseURL = "http://somewebsite.com/~mysite/";//live
function getBaseURL(){
if(test)
return baseTestURL;
else
return baseURL;
}
function generateBase() {
document.write('<base href="' + getBaseURL() + '" />');
}
PS I am aware of a similarly titled thread here (Link). But the answer was not accepted, nor fully addressed the original question. Hence I ask this. Which is a more fuller explanation of the problem which may or may not be related.

log4javascript - no trace messages appear

I'm using log4javascript version 1.4.3.
In my app it works fine for all log levels except trace. To simplify things and make sure that the problem is not within my app I made an example using the authors sample code as an example and added a setThreshold(log4javascript.TRACE), then added a line to generate a trace entry (I also deleted the lines from his example that are relevant only to an ajaxAppender leaving just the popUpAppender).
When I run the code the error and debug messages appear in a log4javascript popUp window but no trace message.
Evidently I don't correctly understand the use of the trace level or the configuration for trace messages. If someone could point out the error of my ways then I can fix my app logging.
Sample code that fails below.
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>log4javascript example from manual</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="Tim Down - tim#log4javascript.org" />
<meta name="description" content="log4javascript, a logging framework for JavaScript based on log4j" />
<meta name="robots" content="all" />
<script type="text/javascript" src="/tracker/libraries/log4javascript.js"></script>
<script type="text/javascript">
//<![CDATA[
var log = log4javascript.getLogger();
var popUpAppender = new log4javascript.PopUpAppender();
var popUpLayout = new log4javascript.PatternLayout("%d{HH:mm:ss} %-5p - %m%n");
popUpAppender.setLayout(popUpLayout);
// new line below
popUpAppender.setThreshold(log4javascript.Level.TRACE);
log.addAppender(popUpAppender);
log.debug("Debugging message (appears in pop-up)");
log.error("Error message (appears in pop-up and in server log)");
// new line below
log.trace("Trace message");
//]]>
</script>
</head>
<body>
<h1>log4javascript example from manual</h1>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-448786-3");
pageTracker._initData();
pageTracker._trackPageview();
</script>
</body>
</html>
The problem is that the logger has a threshold level as well, which is set to DEBUG by default. Add the following line before calling log.trace():
log.setLevel(log4javascript.Level.TRACE);

Loading linked .js with phonegap project

I've scoured the net and stackoverflow looking for help, but can't seem to find any and I consider myself officially stumped. All of my code worked without a problem when it was all within standard script tags, then as soon as I moved them to their own .js file it crapped out. Help! This is what I now have in index.html (I've cut out all the irrelevant code since I'm just testing):
<html>
<head>
<title>PhoneGap Test</title>
<meta name="viewport" content="width=device-width, user-scalable=no;" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" charset="utf-8" src="phonegap-1.3.0.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery/src/lib/jquery-1.7.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery/src/jqtouch-jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery/src/jqtouch.js"></script>
<script type="text/javascript" src="databasecalls.js"></script>
</head>
<body onload="init();">
<p>Some stuff here</p>
</body>
</html>
Then, this is what I have in databasecalls.js:
alert("file loaded");
function init(){
document.addEventListener("deviceready", phoneReady, false);
}
function phoneReady(){
// **** first, open the database ****
alert("Start making DB object");
dbShell = window.openDatabase("TimeBlogger", "1.0", "TimeBlogger", 20000000);
alert("Created DB object");
//and run another function if the setup is successful (displayEntries)
dbShell.transaction(setupDBTable, errorHandler, getDBProjectEntries)
}
So, unless I am mistaken, I should at the very least get alert(); to run as soon as it is read into index.html, right? I'm not even getting that! Is there something with the phonegap API that I missed... like everything needs to be in index.html or something?
Thanks in advance!
Justin

Categories

Resources