I'm building an app which using webView and loading Wikipedia's web pages. I would like to disable this part:
I don't know what is the best way to do this... I have thought of auto scrolling down, but then the user is able to scroll up.
Auto scrolling down is also doesn't accurate and may hide some of the value's information.
Thanks.
By looking into Wikipedia's source code you can see that the search bar is located inside a div container with the class name "header-container header-chrome". You are able to remove it from the view using JavaScripct code and the HTML DOM getElementsByClassName() Method.
The following code might help you with removing the search bar from the HTML page and display the rest.
WebView myWebViewDisply = (WebView) findViewById(R.id.WebViewDisply);
myWebViewDisply.getSettings().setJavaScriptEnabled(true);
myWebViewDisply.setWebViewClient(new WebViewClient() {
#Override
public void onPageFinished(WebView view, String url) {
myWebViewDisply.loadUrl("javascript:(function() { " +
"document.getElementsByClassName
('header-container header-chrome')[0].style.display='none';"
+"})()");
}
});
myWebViewDisply.loadUrl(youUrl);
Related
I am loading a website in my app that contains an element I want to programmatically click (automate the click) as when this is clicked is time sensitive. I have the timing part down but need to trigger this element via an on screen click. I have read that performClick() "should" work but I have no way to verify if its actually clicking in the webview or not. The element in the html I need to trigger with a "touch" is called 'overlay'. Could someone provide me with a template that could do this?
You can use the below snippet to trigger at touch.
Video_Player.my_runnable = new Runnable()
{
#Override
public void run()
{
view.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis() + 50,MotionEvent.ACTION_DOWN,300,300,0));
view.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis() + 50,MotionEvent.ACTION_UP,300,300,0));
}
};
I have an ASP.NET web application and I want to inject a JavaScript SDK to several selected pages during the page load of one specific page(for example HomePage.aspx).
I was thinking of a method like this to call on Page_Load of HomePage.aspx
injectScript(list of selected pages, script){
for each page in selected pages{
page.embed(script)
}
}
But can we use Page.ClientScript.RegisterStartupScript() to register scripts for other pages while calling it from HomePage.aspx?
Is there any better way?
Update 1:
In nutshell, All these pages share a master page but adding this JavaScript SDK to master page will make the SDK available to all child pages. I want to have a way to toggle(on/off) this SDK in each page based on user input(saved in a database).
There are more than 30 aspx pages and adding a method to page_load in each page is not feasible.
Is there any simple way to do achieve this functionality?
In case if anyone wondering the same, here is the solution I came up; use the following method inside Page_Load of the master page.( You will have to populate the list with appropriate data-source)
private void EnableSDK()
{
List<string> pages = new List<string>(); //selected aspx page names(not class names)
foreach (string page in pages)
{
if (page == System.IO.Path.GetFileNameWithoutExtension(Page.AppRelativeVirtualPath))
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "somekey", "somescript", true);
}
}
}
I'm trying to click a button on a webpage (kahoot.it), and I already know that I probably need to use Javascript for that which is fine, as long as it stays with 1 line of JavaScript because that's easy to implement in WinForms. I don't have much information on the button,
only:
<button type="submit" value="Submit" class="enter-button__EnterButton-sc-1o9b9va-0 kxpxeu" data-functional-selector="join-game-pin"><span>Enter</span></button>
Could you guys please help? There's only one button on the page, maybe that helps.
You need to write a piece of javascript code and run it when the page loaded.
Run script after page loaded
To run the code after the page loaded, you can use ExecuteScriptAsyncWhenPageLoaded method or you can handle FrameLoadEnd or LoadingStateChanged.
DOM manipulation - find element, set value, click on button
For the javascript code, you can use any of the available javascript functions. for example find the element using getElemenetsByName, getElementsByTagName or getElementById.
After you found the element, you can set its value or for example for a button you can click on it by calling its click() method.
CefSharp Example - Browse a URL, fill an input and click on a button
The following code, adds a ChromiumWebBrowser control to a Form. Then it browses google and fill the search box with a text and clicks on the search button:
//using CefSharp;
//using CefSharp.WinForms;
ChromiumWebBrowser browser;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
browser = new ChromiumWebBrowser("https://www.google.com/");
browser.Dock = DockStyle.Fill;
Controls.Add(browser);
var script = #"
document.getElementsByName('q')[0].value = 'CefSharp C# Example';
document.getElementsByName('btnK')[0].click();
";
browser.ExecuteScriptAsyncWhenPageLoaded(script);
}
Example 2
In the following example, using ExecuteScriptAsync you can fill the search box with a text and clicks on the search button programmatically:
//using CefSharp;
//using CefSharp.WinForms;
ChromiumWebBrowser browser;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
browser = new ChromiumWebBrowser("https://www.google.com/");
browser.Dock = DockStyle.Fill;
Controls.Add(browser);
}
private void button1_Click(object sender, EventArgs e)
{
var script = #"
document.getElementsByName('q')[0].value = 'CefSharp C# Example';
document.getElementsByName('btnK')[0].click();
";
browser.ExecuteScriptAsync(script);
}
Note: In your case, for kahoot.it, the script should be:
var script = #"
document.getElementById('game-input').value = '123';
document.getElementsByTagName('button')[0].click();
";
Changing Target Framework version to 4.7.2 from 4.0 fixed for me
True Target Framework Version
What I am wanting to do is simple. I am using UrbanAirship to show a modal view ("In-app Automation"), which is HTML. I have a button in my HTML. The message/view is showing fine when the event is fired. Right now I have in the HTML for the button:
<button class="light" type="button" onclick="UAirship.close()">OK</button>
When the button is tapped, the call to UAirship.close() works fine and closes the message. I setup a listener in my Android code, such as follows:
UAirship.shared()
.getInAppMessagingManager()
.addListener(new InAppMessageListener() {
#Override
public void onMessageDisplayed(#NonNull String scheduleId, #NonNull InAppMessage message) {
// gets here fine
}
#Override
public void onMessageFinished(#NonNull String scheduleId, #NonNull InAppMessage message, #NonNull ResolutionInfo resolutionInfo) {
// gets here fine as well
}
});
It gets into those methods without any issues when the message/view shows and dismisses. However, I want to be able to detect one particular button was tapped vs. others I have in the HTML. Is there a way to go about this easily, so that some custom tag or something can be passed in the "ResolutionInfo" object or "InAppMessage"?
My hopes were that there would be something like "UAirship.close('tag')", where that tag would be passed back. Or even a custom HTML tag I can put on the button that would be recognized in the code. Really just any way of going about it is fine, I just can't seem to find in the documentation how to properly do this with HTML.
I'm looking at the documentation here. I see the UAirship.runAction() method, but it's not really clear to me what a simple implementation would be for this (also, the "CustomAction" class referenced in the action registering doesn't even exist in the library it seems..).
I basically just need to call one line of code in my Activity when the Airship message closes after that button is tapped.
Thoughts?
I've found that this solution works, although there may be a better one out there.
In the HTML, for the button, call the close() and then a runAction() call:
onclick="UAirship.close(); UAirship.runAction('my_action', null, null)"
Then in the code, in my onCreate() in my Activity, I have this:
final String actionName = "my_action";
Action customAction = new Action() {
#NonNull
#Override
public ActionResult perform(#NonNull ActionArguments actionArguments) {
String buttonActionName = actionArguments.getMetadata().getString(ActionArguments.REGISTRY_ACTION_NAME_METADATA);
if (buttonActionName.equals(actionName)) {
// DO WHAT IS NEEDED HERE
}
return ActionResult.newEmptyResult();
}
};
UAirship.shared()
.getActionRegistry()
.registerAction(customAction, actionName);
I have been trying to get the status bar to go away as i want to put a fullscreen game in.
i'm using phonegap for the iphone
thanks in advance.
For iPhone simply add
<key>UIStatusBarHidden</key>
<true />
in your [appname]-info.plist file
For completeness if you also wish to roll out for android this solution worked well
In the file where you change activity to droidgap
public class app extends DroidGap
Add the following import
import android.view.WindowManager;
And then append the following within the class method
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.loadUrl("file:///android_asset/www/index.html");
}
Hope this helps
regards
If you want to the app to load with the status bar initially hidden:
[appname]-info.plist file
Find "Status bar is initially hidden"
Add new row if it isn't already there
Select 'YES' for the value
"Status bar is initially hidden" is the key that is available at least in xcode 4.2 beta 5.
You can try:
1) call this:
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO]
2) or this from your view controller.
[self setWantsFullScreenLayout:YES];
3) You can do it from the Interface Builder. Here's a video about it:
http://www.youtube.com/watch?v=aPAChohC-4Q
4) Someone else asked the same thing and got some related answers:
Fullscreen UIView with Status bar and Navigation Bar overlay on the top
For iOS7, you'll need to set the following setting in your [appname]-info.plist:
'View controller-based status bar appearance' to NO (Boolean)