I have a text message that my ionic app retrieves from an api that has an anchor link which needs to redirect to another page when tapped.
The html from the api is:
Tap Here
The ionic function is:
goToOtherPage(): void {
this.navCtrl.push(OtherPage);
}
I have tried:
<a onclick="goToOtherPage()">Tap Here</a>
and
Tap Here
but the first two give the message:
goToOtherPage is not defined
and the last one does nothing.
Does anyone know how I can trigger a function from dynamically retrieved html?
This will not work due to the DomSantizer that sanitizes unsafe html. I recommend retrieving the different parts of the message (eg. using JSON) and generating the page link and message via your page/component.
Related
I am stuck at one of the issue where I have a anchor tag in a component , on click of It ,I have a post method which is posting some data into service and in response I am getting report data as a html string , Now client wants to see the report as a PDF in a new window . How to achieve this ,there are lots of articles but none of it resolved ,need some simple solution . Somewhere I read to convert html string in service to byte of array using encode and then Create Url Object (front end -Blob) but that is also not working. I dont have the exact code but a kind of replica I just shared ,any help would be great.
<a (click)= "openreport(request)" />
openreport(request) {
this.dataservice.postdata('service url' ,request).subscribe(res= >{
res.creditreportdata---> html string
})
}
I'm developing a ASP.NET Core web application where I'm using DataAnnotations to decorate my view model with validation attributes. When I open a detail page with my inputs, I see that Core added the HTML5 validation attributes to the rendered HTML (i.e. data-val="true").
However, I wrote custom client-side code when the user clicks on the Save button like this:
$(document).on("click", "#SaveAsset", function (event) {
event.preventDefault();
Asset.Save();
});
I also have a Save function defined like this:
window.Asset.Save = function () {
var postData = {
'Id': $("#Id").val(),
'SerialNumber': $("#SerialNumber").val(),
'PartNumber': $("#PartNumber").val(),
'assetTypeId': $("#AssetTypeId").val()
};
$.post('/Asset/SaveAsset', postData);
}
I need to validate on the client side first before calling $.post but I'm confused about how to do it. Microsoft shows that the unobtrusive javascript works automatically when you use it with forms. But I'm not using the HTML form element to submit my page. So how can I trigger the HTML5 validation attributes?
I added the links to jquery.validate.js and jquery.validate.unobtrusive.js. Right now, if I click the Save button the data is sent to the server and the controller checks the ModelState. But it shouldn't even be sending anything to the server. The client should stop the validation.
Should I even stop doing it this way? For example, creating my postData JSON object by getting the val() of each input.
Should I use the form element? I stopped using it because my page has hundreds of inputs so I was worried I would have problems. This way, I have control over each input.
Use a javascript solution like jQuery Validation Plugin to validate data before sending to the server. Otherwise, send the data to the server, and return a the errors with a bad request if validation fails.
Eg.
Return BadRequest(string[]{"Name is required", "Id must me a number"});
then capture the errors and shoe to the user
For a Google site, I want a page to display content based on the url parameters.
Eg. http://sites.google.com/../mypage?id=123
Then I want to make a HTTP request using the id and display the result on the page.
Or I want to use App Scripts to perform something and display the result on the page.
How can I do so?
Use on Google app script
function doGet(e){
// id in your Url. example : http://sites.google.com/../mypage?myidok=123
var element - e.parameters.myidok
// code
// your app
}
See this answer for an example of serving multiple html pages using HtmlService. The basic idea is to write doGet() to accept a query parameter that it will use to select which html page to serve.
in Blackberry Cascades (C++, QT, QML), I am trying to read the html of a webview - but it is returning blank. This webview uses "setUrl(url") to set the url, and does not use "setHtml(html)". Anyway - I have this code:
WebView {
id: loginView
objectName: "loginView"
onMicroFocusChanged: {
console.log("html: " + html);
}
}
And the webview url has two textfields, and when I put my cursor into those text fields or when I type in them, the html of the webview shows up as blank - but I need to see the html, because I am trying to be able to parse that html to get the content of those textfields.
How come the html is blank - and how can I get access to this html?
The Html property of the WebView only returns the code that was inserted with setHtml. (Documentation)
Even if it did report code loaded from a web address, I doubt it would be updated with the current value of textboxes.
To read their content, I recommend you look into the messageReceived signal of the WebView. If you can change the html-code that contains your text boxes, you can use javascript navigator.cascades.postMessage() to send the data to your application.
If you do not control the html, you can still use the evaluateJavaScript method to extract the values of the textboxes with DOM functions from inside your app.
First let me set the situation.
I am writing a simple client html page and a simple server side program.
In detail, the page has a submit button to POST some data to the server program.
The problem is that any time I test the page to push the submit button ,the browser displays the new page which displays only the return message my server program returned.
How can I modify the html or the server side program so that the browser keeps the page unchanged before after the submit button is pushed.
I know an easiest way ; letting the sever program returns the same string as the client html page.
Thank you in advance.
In a regular form submission, your page will be whatever the server sends back. The form's action might be the same page, and then your server-side code can read the value of any input fields, and set the values in the response back to what they were in the request. This should result in the page looking the same as it did before the submit button was pressed. However, the page has "changed" in the sense that it was reloaded.
Alternatively, your form can make an Ajax request, which means that you'd need to use Javascript to intercept and stop the form submission, and then use additional coding to send the Ajax request, and then receive and process the response.
What you want is probably a postback:
http://en.wikipedia.org/wiki/Postback
1.) AJAX
You could use JavaScript and AJAX to POST the data.
2.) IFrame (not recommended)
You could also create a hidden IFrame and set the target attribute of the form to it.
What you want to do doesn't seem to be very clear.
If you want to submit your POST data without loading a new web page, you can use Ajax. It may be simple to do it in jQuery, and even simpler if you serialize your form data.
$('form').submit(function() {
$.post('your-post-url',$(this).serialize(),function(data) {
alert('Data posted!');
});
return false;
});