mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Test page
This commit is contained in:
@@ -13,6 +13,7 @@ export function pageLoaded(args: EventData) {
|
||||
|
||||
examples.set("webview", "web-view/web-view");
|
||||
examples.set("webtest", "web-view/web-view-test");
|
||||
examples.set("query", "web-view/query-params");
|
||||
|
||||
let viewModel = new SubMainPageViewModel(wrapLayout, examples);
|
||||
page.bindingContext = viewModel;
|
||||
|
||||
38
apps/app/ui-tests-app/web-view/query-params.ts
Normal file
38
apps/app/ui-tests-app/web-view/query-params.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { WebView } from "tns-core-modules/ui/web-view";
|
||||
import * as fs from "tns-core-modules/file-system";
|
||||
|
||||
let webView: WebView;
|
||||
export function webViewLoaded(args) {
|
||||
webView = args.object;
|
||||
}
|
||||
|
||||
const relUrl = "~/ui-tests-app/web-view/query.html" + "?foo=bar&urlType=relative";
|
||||
const absoluteUrl = `${fs.knownFolders.currentApp().path}/ui-tests-app/web-view/query.html` + "?foo=bar&urlType=absolute";
|
||||
const fileUrl = `file:///${fs.knownFolders.currentApp().path}/ui-tests-app/web-view/query.html` + "?foo=bar&urlType=filePrefix";
|
||||
const htmlString = `<html>
|
||||
<head>
|
||||
<title>Test Page</title>
|
||||
<meta charset="utf-8" />
|
||||
</head>
|
||||
<body>
|
||||
<div style="color:green" id="result">Just a string ...</div>
|
||||
</body>
|
||||
</html>`;
|
||||
|
||||
export function loadRelative() {
|
||||
setSrc(relUrl)
|
||||
}
|
||||
export function loadAbsolute() {
|
||||
setSrc(absoluteUrl)
|
||||
}
|
||||
export function loadFile() {
|
||||
setSrc(fileUrl)
|
||||
}
|
||||
export function loadString() {
|
||||
setSrc(htmlString)
|
||||
}
|
||||
|
||||
function setSrc(src) {
|
||||
console.log("Setting src to: " + src);
|
||||
webView.src = src;
|
||||
}
|
||||
10
apps/app/ui-tests-app/web-view/query-params.xml
Normal file
10
apps/app/ui-tests-app/web-view/query-params.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<Page>
|
||||
<GridLayout rows="* auto" columns="* * * *">
|
||||
<WebView colSpan="3" src="someUrl | pathToLocalFile | htmlString" loaded="webViewLoaded" />
|
||||
|
||||
<Button row="1" col="0" text="rel" tap="loadRelative"/>
|
||||
<Button row="1" col="1" text="abs" tap="loadAbsolute"/>
|
||||
<Button row="1" col="2" text="file" tap="loadFile"/>
|
||||
<Button row="1" col="3" text="str" tap="loadString"/>
|
||||
</GridLayout>
|
||||
</Page>
|
||||
28
apps/app/ui-tests-app/web-view/query.html
Normal file
28
apps/app/ui-tests-app/web-view/query.html
Normal file
@@ -0,0 +1,28 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Test Page</title>
|
||||
<meta charset="utf-8" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h3>Result</h3>
|
||||
<div style="color:green" id="result">No value yet</div>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
function getParameterByName(name) {
|
||||
url = window.location.href;
|
||||
name = name.replace(/[\[\]]/g, "\\$&");
|
||||
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
|
||||
results = regex.exec(url);
|
||||
if (!results) return null;
|
||||
if (!results[2]) return '';
|
||||
return decodeURIComponent(results[2].replace(/\+/g, " "));
|
||||
}
|
||||
|
||||
var res = document.getElementById("result");
|
||||
res.innerHTML = "foo: " + getParameterByName("foo") + "<br>" + "urlType: " + getParameterByName("urlType");
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user