Is in windows phone equivalent of IOS method called loadHTMLString:baseURL or android loadDatawithBaseUrl (here). I want to run script on website and that is why I need this base url to be invoked.
By looking at the reference link, I think what you are trying to achieve is a web browser control on Windows Phone to display a remote HTML page on the app page.
LOAD FROM REMOTE URL:
Step 1: Load WebBrowser control on your app page from the Toolbox on page.xaml
<Grid x:Name="ContentGrid" Grid.Row="1">
<phone:WebBrowser HorizontalAlignment="Left" Margin="0,0,0,0" Name="webBrowser1" VerticalAlignment="Top" Height="800" Width="470" />
</Grid>
Step 2: Write C# code (you can even use VB.NET) on page.xaml.cs
webBrowser1.Source = new Uri("http://www.foo.com", UriKind.Absolute);
LOAD FROM LOCAL HTML STRING
Here Step 1 remains the same, just to load an HTML code locally:
Step 2: C# Code on page.xaml.cs
String htmlContent = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=windows-1250\">
<meta name=\"spanish press\" content=\"spain, spanish newspaper, news,economy,politics,sports\">
<title></title>
</head>
<body id=\"body\">
<!-- The following code will render a clickable image ad in the page -->
<script src=\"http://www.myscript.com/a\"></script>
</body>
</html>";
webBrowser1.NavigateToString(htmlContent); //This renders the HTML string defined above in the webview.
EDIT: Also, if you want to allow scripts to execute in the webview, set IsScriptEnabled property of the webbrowser control to true.
webBrowser1.IsScriptEnabled = true;
Related
i have tried the following :
t.switchTo("frameID");
var ele = Selector("#ele");
await t.click(ele);
another attempt :
Selector(() =>{return document.getElementById("frameId").contentDocument.getElementById("#ele")});
This throws the following error : Function for selector should return DomElement, NodeList, HtmlCollection, NULL or undefined.
The HTML DOM is as follows :
<html>
<body>
<frameset>
<frame id='frame1'>
#document
<html>
<body>
<p id='ele1'>Hello World</p>
</body>
</html>
</frame>
</frameset>
</body>
</html>
The frame and frameset features are marked as obsolete in the W3C Recommendation. As TestCafe is based on HTML5 standards that do not support frameset, TestCafe does not support frameset either. So, we'd like to focus on up-to-date features, which will give the best experience in testing modern web applications.
As for the example you shared, you can use this test:
test('test', async t => {
await t.click('#ele1');
})
im trying to upload to this form with vb.net
<head>
<title></title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="/css/login.css">
</head><meta charset="UTF-8">
<form method="post" action="/addData">
<input type="text" name="id"/>
<textarea name="data"></textarea>
<input type="submit" name="add" value="go"/>
</form>
and here is the vb code
Dim data2 As New System.Collections.Specialized.NameValueCollection()
data2.Add("id", TextBox1.Text)
data2.Add("data", TextBox2.Text)
data2.Add("add", "go")
Dim client As New System.Net.WebClient
client.UploadValues("link", data2)
any idea what im doing wrong here?
im always getting error 404, but it's not right.
because i did simple check by showing msgbox displaying the page source.
and it worked
We can't say much from that (at least I can't).
What you should do is inspect the POST request you send (via your regular browser) that way you will know what you need to send.
For example, here is how the POST request looks like for posting this answer.
qualityBanWarningShown=false&referrer=https%3A%2F%2Fstackoverflow.com%2Fquestions%2Ftagged%2Fvb.net&post-text=We+can't+say+much+from+that+(at+least+I+can't).%0D%0A%0D%0AWhat+you+should+do+is+inspect+the+POST+request+you+send+(via+your+regular+browser)+that+way+you+will+know+what+you+need+to+send.&fkey=<something>&author=&i1l=<something>
The form sends its POST to /addData, which means you need to do so as well. If you're trying to POST to the page which's code you've shown above it won't work.
The URL starts with a slash (/), meaning addData is located in the website's root directory. Thus you should send your POST to: http://www.website.com/addData (or https:// depending on what the website is using).
Is there any way to detect whether or not an image has not loaded/is broken in a webbrowser control? I am loading html from a file like so:
Here is some html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META content="text/html; charset=unicode" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 11.00.10586.589">
</HEAD>
<BODY>
<A href="https://web.archive.org/web/20120124023601/http://www.flatfeets.com/wp-content/uploads/2012/01/shoes-for-flat-feet.jpg">
<IMG title="shoes for flat feet" class="alignleft size-medium wp-image-18" alt="" src="https://web.archive.org/web/20120124023601im_/http://www.flatfeets.com/wp-content/uploads/2012/01/shoes-for-flat-feet-300x238.jpg">
</A>
</BODY>
</HTML>
And simple load this into webbrowser
webbrowser1.DocumentText = thehtml
I would just like to be able to detect whether or not the image has loaded properly. This should work for all images on the page.
You could create a separate WebClient request for each image in the html file and then see if any return a html response error code.
You would first have to parse the html and make a list of all the images urls. I would suggest using a package like HTML Agility Pack to easily parse out the image urls. Then you could use this code to identify any bad paths.
WebClient requester = new WebClient();
foreach (string url in urls)
{
try
{
Byte[] imageBytes = requester.DownloadData(url);
}
catch(Exception ex)
{
//Do something here to indicate that the image file doesn't exist or couldn't be downloaded
}
}
You can also convert the byte array to an Image and then make sure that it is RGB Encoded since that is the only encoding that can reliably be displayed in a web browser.
I have a partial view rendered with an Html.Action() that I want to refresh on a button click. I've tried AJAX requests, but the data I'm passing back and forth exceeds the maximum length for JSON.
The basic structure of the page looks like:
<html>
<head>
...
</head>
<body>
<div>
#Html.Action("DisplayBox")
</div>
<div>
<input type="button" id="RefreshButton" value="Refresh Box" />
</div>
</body>
</html>
The reason why I'm asking for a method other than an AJAX request is that the partial I'm rendering is a PDF object:
#model byte[]
#{
String base64EncodedPDF = System.Convert.ToBase64String(Model);
Layout = null;
}
<object data="data:application/pdf;base64,#base64EncodedPDF"
width="900" height="900" type="application/pdf"></object>
Thus, the data passed to the partial view for rendering is too big to put in an AJAX request. On button click, I want to be able to execute the controller action and have the results update the partial with new data. Is there any way of doing this?
You have to load the HTML with the link to the controller that generate the PDF or generate the file on the server side, host it and return the URL of this PDF, then, javascript can redirect user to that file.
I don't think that returning file trough AJAX is really not a good practice!
I've got a iframe with pdf file:
<iframe src="pdf/sample.pdf"></iframe>
How to set that the iframe is the same height as the pdf file, without scrollbars?
If you want to display the PDF without scrollbars, you can do this by passing parameters in the URL. Adobe has documented this here:
http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf
Try this:
<iframe src="pdf/sample.pdf#view=fit"></iframe>
You are not exactly setting the height of the iframe to fit the PDF, but it is probably the most robust solution since it is browser-independent and doesn't require JavaScript.
Here is an update after Daniel's comment.
I created a test HTML as follows:
<!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">
<head>
<title>Untitled Page</title>
</head>
<body>
<iframe src="http://partners.adobe.com/public/developer/en/pdf/PDFReference.pdf#view=fit&toolbar=0&navpanes=0"
width="300px" height="400px"></iframe>
</body>
</html>
This is how it looks in Chrome:
This is as expected.
Note that I also turned off the toolbar and the navpane so there is room for the page.
You can do it simply using the method I've explained on my facebook post https://www.facebook.com/antimatterstudios/posts/10151007211674364
Do you have an IFrame, which you want to automatically set the height of because you're hosting a page from another website in yours.
Well, unfortunately the IFrame cannot take the height of the content you are loading and unless you put a height, it'll show either the default height, or no height at all. This is annoying.
I have the solution for you, it'll only work on recent, standard supporting browsers, but also works in IE8 too, so for about 99% of you it's perfect.
The only problem is you need to insert a javascript inside the iframe, which is easy if the content you are loading belongs to you, you can just open the content you're loading and put the javascript in the content.
In your website, you need a piece of javascript which can "receive a message from the IFrame", like this
jQuery(document).ready(function(){
jQuery(window).bind("message",function(e){
data = e.data || e.originalEvent.data;
jQuery("iframe.newsletter_view").height(data.height);
});
});
in your IFrame content, add this at the very bottom, probably it's ok to just do something like "$template.$javascript" using PHP or something, even if the javascript is not inside the tag
<script type="text/javascript" src="jquery-1.7.1-min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
parent.postMessage({
height:$(document.body).height()+50+"px"
},"*");
});
</script>
Obviously I am using jquery, you dont have to, it's just easier and probably you are using it, so save yourself the hassle.
if you do that, when the iframe loads, it'll send a signal back to the parent window, which will resize the iframe based on the length of the content :)
I'm sure you can figure out how to alter the little things, but thats the method I'm using
My solution
$(document).ready(function(){
var width = $(window).width();
var height = $(window).height();
$('#objFile').attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');
});
<object data="myFile.pdf" type="application/pdf" id="objFile"></object>