ChromiumWebBrowser - how to set height to HTML doc height - html

I have a chromiumWebBrowser hosted in my application.
user can navigate between html pages (with binging to address).
I need xaml scroller (not css), so I have a scrollViewer and inside the Chromium browser.
Every time the Address changes, chromium height needs to be full html doc height, to get the scrolling right.
I have tried setting it similar to answer in this Q:
cefSharp ChromiumWebBrowser size to page content
which works well first time, but when navigating, it only grows - if first page is 600, and next is 200 - it returns 600 second time too.
XAML:
<ScrollViewer x:Name="scroller" >
<wpf:ChromiumWebBrowser x:Name="chrome"
Address="{Binding CurrentUrl}" />
</ScrollViewer>
C#:
chrome.LoadingStateChanged += async (s, e) =>
{
if (!e.IsLoading) // browser.CanExecuteJavascriptInMainFrame == TRUE !
{
JavascriptResponse response =
await chrome.EvaluateScriptAsync(
// GET HEIGHT OF CONTENT
$"(function() " +
"{ var _docHeight = " +
" document.documentElement.scrollHeight; " +
" " +
" return _docHeight; " +
"} " +
")();");
int docHeight = (int)response.Result;
chrome.Dispatcher.Invoke(() => { chrome.Height = docHeight; });
}
};

Related

First span (onclick) of html page not working

I have an Html page with cards this is my jade code:
div(id="myModal" + i class="modal")
div(class="modal-content")
span(class="close" onclick="closeMoviePopup(#{i})") ×
h2= movie.name
a(href="sodaplayer:?url=" + movie.magnet_link + "&title=" + movie.name onclick="(function(){ document.getElementById('myModal#{i}').style.display = 'none'; })();return true;") Stream
js:
function closeMoviePopup(index) {
document.getElementById('myModal' + index).style.display = 'none';
}
For some reason, every card works except the first one I don't understand why that would happen. It is not a problem with the i variable or the function I don't get what it is
Because in you index.js you are capturing the first span var span = document.getElementsByClassName("close")[0]; and executing a different function. Fix
that and it should work.

How to program a URL? (For search query)

A co-worker of mine shared an autohotkey script (it's actually an exe file that runs on the background). Anyways, when I click the hotkeys it opens up a company webiste and creates a shared query for whatever's on the clipboard. I was wondering how this is done and how I can make my own.
I'm specially curious about the "URL" modification that includes all these search options:
https://<COMPANYWEBSITE>/GotoDocumentSearch.do
That's the URL where I can search (sorry it's restricted and even if I link it you cant access it).
Anyways, after I set up all my options and stuff and click the search button I get the following URL:
https://<COMPANYWEBSITE>/DocumentSearch.do
I inspected the website source and this is the function that's called when I press the search button:
function preSubmitSearch(docPress) {
document.pressed = docPress;
// setup local doc types for submit by lopping over multi selects and building json data string
var localDocTypesJson = "{";
var sep = "";
jQuery(".localTypeSel").each(function (i) {
var selLocalTypes = jQuery(this).multiselect("getChecked");
// get doc type code from id ex. 'localTypeSel_PD'
//window.console.log("this.id=" + this.id);
var tmpArr = this.id.split("_");
var docTypeCode = tmpArr[1];
var selLocalTypesCnt = selLocalTypes.length;
if (selLocalTypesCnt > 0) {
var localTypes = "";
var sep2 = "";
for (var i2 = 0; i2 < selLocalTypesCnt; i2++) {
localTypes += sep2 + "\"" + selLocalTypes[i2].value + "\"";
sep2 = ",";
}
localDocTypesJson += sep + "\"" + docTypeCode + "\": [" + localTypes + "]";
sep = ",";
}
});
localDocTypesJson += "}";
jQuery("#localDocTypesJson").val(localDocTypesJson);
}
HOWEVER, the working code that was shared with me (that was written ages ago by some employee who's not here anymore). Has the following URL when I use the autohotkey:
https://<COMPANYWEBSITE>/DocumentSearch.do?searchType=all&localDocTypesJson=7D&formAction=search&formInitialized=true&searchResultsView=default&btn_search=Search&docName=*<CLIPBOARD>*&wildcards=on&docRevision=&latestRevOnly=true&docProjectNumber=&docEngChangeOrder=&docLocation=&findLimit=500&docTypes=Customer+Drawing&docTypes=Production+Drawing&docTypes=Manufacturing+Process+Document&docTypes=Specification+Or+Standard
Note: replaced text with "CLIPBOARD" for clarification.
I was wondering if that's a type of "URL-programming" or how can I make a direct URL that prompts for the search results from the website? is that Javascript? or how is that programmed? (I know Swift and some Java, but have never really used Javascript).
It doesn't seem like you are asking an AutoHotKey (AHK) question, but to give you an AHK example you can copy, here is how I would use AHK to use Google.com to search for whatever is in my clipboard:
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := true
wb.Navigate("https://www.google.com/search?q=" . StrReplace(Clipboard, " ", "+") . "", "")
Note, the URL format includes the query ("?q=whatever+you+had+in+Clipboard") in it with spaces replaced by "+"s.
Hth,

How do I get output to the webpage while still inside a cfscript?

Sorry for the longer post, I'm trying to be specific. I'm a bit of a newb at cold fusion and lucee, so forgive me if I have missed something fundamental here. I'm just trying to do a quick POC, but can't get it working. What I am trying to do is make a page call, write to a web page, sleep for a while. Kind of a heartbeat. What I can't get to happen is the write to the web page...until all sleep(s) have happened and the page cfm file completes processing. I've looked extensively for the past couple of days, and have tried numerous items, but to no avail. From my index.cfm lucee page, I have a link to launch a new tab and call my cfm file.
<a href="./pinger2.cfm" target="_blank"><img class="ploverride" src="/assets/img/Ping.png" alt="Ping Test" width="125" height="75">
No problem here, a new tab opens and pinger2.cfm starts processing.
What I'm hoping for is the table heading to almost immediately print to the page, then make the first call out, print the results to the page, sleep, make the next call out, print to the page...but it no workey. Anyone have a clue? The code in the pinger2.cfm file is:
<cfscript>
public struct function pinger( required string url, required string verb, required numeric timeout, struct body )
{
var result = {
success = false,
errorMessage = ""
};
var httpService = new http();
httpService.setMethod( arguments.verb );
httpService.setUrl( arguments.url );
httpService.setTimeout( arguments.timeout );
if( arguments.verb == "post" || arguments.verb == "put" )
{
httpService.addParam(type="body", value=SerializeJSON(arguments.body));
}
try {
callStart = getTickCount();
var resultObject = httpService.send().getPrefix();
callEnd = getTickCount();
callLength = (callEnd-callStart)/1000;
if( isDefined("resultObject.status_code") && resultObject.status_code == 200 )
{
result.success = true;
logMessage = "Pinger took " & toString( callLength ) & " seconds.";
outLine = "<tr><td>" & resultObject.charset & "</td><td>" & resultObject.http_version & "</td><td>" & resultObject.mimetype & "</td><td>" & resultObject.status_code & "</td><td>" & resultObject.status_text & "</td><td>" & resultObject.statuscode & "</td><td>" & logMessage & "</td></tr>";
writeOutput( outLine );
getPageContext().getOut().flush();
return result;
}
else
{
throw("Status Code returned " & resultObject.status_code);
}
}
catch(Any e) {
// something went wrong with the request
writeDump( e );
abort;
}
}
outLine = "<table><tr><th>charset</th> <th>http_version</th> <th>mimetype</th> <th>status_code</th> <th>status_text</th> <th>statuscode</th> <th>time</th> </tr>";
writeOutput( outLine );
getPageContext().getOut().flush();
intCounter = 0;
while(intCounter LT 2)
{
theResponse = pinger(
url = "https://www.google.com",
verb = "GET",
timeout = 5
);
intCounter = intCounter + 1;
getPageContext().getOut().flush();
sleep(2000);
}
outLine = "</table>";
writeOutput( outLine );
</cfscript>
NOTE: I'm sure there are other "less than best" practices in there, but I'm just trying to do this quick and dirty.
I thought the getPageContext().getOut().flush(); would do the trick, but no bueno.
EDIT: If it matters, I'm using CF version 10,0,0,0 and Lucee version 4.5.2.018.
I do something similar to generate ETags by hand (using Lucee 4.5). I stick a simple
GetPageContext().getOut().getString()
in the onRequestEnd function in Application.cfc. This returns a string of HTML just like it's sent to the browser.
You could store that in the appropriate scope (APPLICATION, SESSION, etc) and use it later, or whatever you need. Obviously, all processing needs to be completed, but it shouldn't require any flushes. In fact, flushing may or may not alter its behavior.

jquery button works fine first time but second time not working

I created a very simple index.html file and inside I included some jquery script. You can see below:
<script>
$(document).ready(function(){
var $tweets = $('.tweets');
var current_position = -1;
function getTweets(){
var index = streams.home.length - 1;
var cp = index;
while(index >= current_position + 1){
var tweet = streams.home[index];
$tweets.append('<div class="twe"><span class="name" style="color:blue">' + '#' + tweet.user + ': ' + ' </span><span class="message">' + tweet.message + tweet.created_at + '</span></div>');
index--;
}
current_position = cp;
}
getTweets();
$('button').click(function(){
getTweets();
});
$('.name').click(function(){
$tweets.prepend('<div>' + 'objname' + streams.home.length + '</div>');
});
});
</script>
there is one button used for updates all the tweets and dynamically put them in the section with class="tweets" part. And this button works fine no matter how many times I press it.
Then I add click event to all those with class name 'name' and once I click it , it will add 'objname' + streams.home.length to the front of my
section class="tweets" part. The problem is first time , I CLICK the $('.name') it works fine , but later after I added more items through $('button') click event. it seems the new created $('.name') items is not clickable which means they don't generate 'objname' + streams.home.length to the front of my
section with class="tweets" part. I am really confused here and don't know why.
try following
$("body").on("click",".name",function(){
$tweets.prepend('<div>' + 'objname' + streams.home.length + '</div>');
});
As your element gets added runtime on the page, it needed to be taken care separately with help of "on" which bind events automatically when event gets created.
check reference

How to get the map zoom action on Ti.map

There are articles about ti.map.
Map
View
I found some entry about zoom.
However I couldn't figure out how to get the map zoom level,
when user pinch the maps on devices.
I tried like this but in vain.
var mapView = Map.createView({
mapType:Map.NORMAL_TYPE,
userLocation:true,
region: {latitude:35.699058, longitude:139.326099,
latitudeDelta:0.01, longitudeDelta:0.01},
animate:false,regionFit:true,
userLocation:true,
});
mapView.addEventListener('pinch', function(evt) {
Ti.API.info("pinch " + evt);
//This is not fired.
});
mapView.addEventListener('click', function(evt) {
Ti.API.info("Clicked " + evt.clicksource + " on " + evt.latitude + "," + evt.longitude);
// This is fired.
});
Thanks to #Fokke Zandbergen's help
I solve the problem.
mapView.addEventListener('regionChanged',function(evt){
Ti.API.info('regionchanged delta lati,longi ' + evt.latitudeDelta + "," + evt.longitudeDelta);
if (evt.latitudeDelta > 0.020){
// do something.
}
});
I think you can achieve your goal by listening to the regionchanged event of the view. You'll get the region displayed, but there's zoom level. Depending on what you need it for you'll have to use the region to calculate that yourself.