I am parsing CSS file, and receive background-image property value in CSS, but the URL is not a full URL. It looks like this url(../images/logo.png)
How to get a full URL link for background-image property in CSS like http://www.aaa.aaa/aaa/aaa/aaa.png OR How to get an URL link for the image folder which contains that specific image?
You can get the absolute path by using Server.MapPath
var absoluteUrl = this.Server.MapPath("../images/logo.png".Replace("..","~"));
This will result in http://www.yoursite.com/images/logo.png
Related
I'm trying to validate image on website however can't access the url of the image.
Most websites will have the image with a "src" tag however this website has the url imbedded in another tag.
Iv used return driver.FindElement(By.ClassName("p-image__image--contain")); to access the element and used GetAttribute("style"); to access the image url. However the only information given was background-position: center center;
html format
When you use GetAttribute("style"), it will only return whatever was in the actual style attribute on the element, but many CSS attributes are actually applied using class stylesheets or other ways. So instead you should use the GetCssValue method, like so:
element.GetCssValue("background-image")
getCssValue(); will help in this case
WebElement img = driver.findElement(By.className('imgClass'));
String imgPath = img.getCssValue("background-image");
you will got full values in imgPath, Value like url("imageURL") then you need to use regex OR get values by slip function
I hope this scenario will help
I'm able to load a local HTML file into my WebView like this (this works fine):
var fileName = "Views/Default.html";
var localHtmlUrl = Path.Combine(NSBundle.MainBundle.BundlePath, fileName);
var url = new NSUrl(localHtmlUrl, false);
var request = new NSUrlRequest(url);
WebView.LoadRequest(request);
I'd like to reference a CSS file (also local) in my HTML file:
<link href="Content/style.css" rel="stylesheet">
The CSS file does exist inside of a Content folder, the build action is set to Content for said file.
How can I reference/load the CSS file in question via my html file? Possible?
UPDATE: Had css and html in separate folders. Put them both in a Content folder then updated the hrefs which solved the issue while using LoadRequest.
Check this link
https://developer.xamarin.com/recipes/ios/content_controls/web_view/load_local_content/
Section Additional information
Html generated in code can also be displayed, which is useful for customizing the content. To display an Html string, use the LoadHtmlString method instead of LoadRequest. Passing the path to the Content directory helps the web view resolve relative Urls in the Html, such as links, images, CSS, etc.
// assumes you've placed all your files in a Content folder inside your app
string contentDirectoryPath = Path.Combine (NSBundle.MainBundle.BundlePath, "Content/");
string html = "<html><a href='Home.html'>Click me</a></html>";
webView.LoadHtmlString(html, new NSUrl(contentDirectoryPath, true));
I have a website that is working fine with Razor (C#) all the coding is working properly when I use my local testing (WebMatrix IIS).
When I put it "online" on my server the website is not at the root of the site it self
For example:
http:// intranet.mycompany.com/inform
That's basically the "root" of my folder structure so all my folders starts from there (css file default.cshtml... and so on)
My "_PageStart.cshtml" sees it properly cause when I access my site from the link http://intranet.mycompany.com/inform it gives me the Layout I have configured in _PageStart.cshtml (and it really show the layout + the rendered default.cshtml)
BUT nothing else is getting the proper path, for example :
<img src="~/images/logos/hdr.png" />
The img holder is there I can see it but shows that the link is broken... when I Right-Click the img holder and do properties to see where the files should be it shows me :
http:// intranet.mycompany.com/images/logos/hdr.png
So it's going to the "full" root not the relative root...
How can i fix that ?
You have to use relative paths all over your app:
~ won't work within static html code.
You can write
<img src="#Url.Content("~/images/logos/hdr.png")" />
or
<img src="../images/logos/hdr.png" />
The first approach is good for layout files where your relative path might be changing when you have different length routing urls.
EDIT
Regarding to your question about normal links:
When linking to another page in your app you don't specify the view file as the target but the action which renders a view as the result. For that you use the HtmlHelper ActionLink:
#Html.ActionLink("Linktext", "YourController", "YourAction")
That generates the right url for you automatically:
Linktext
EDIT 2
Ok, no MVC - so you have to generate your links yourself.
You have to use relative paths, too. Don't start any link with the / character!
Link
Link
Link
EDIT 3
When using Layout pages you can use the Hrefextension method to generate a relative url:
<link href="#Href("~/style.css")" ...
Use Url.Content as shown bellow:
<img src="#Url.Content("~/images/logos/hdr.png")" />
I know that '~' is added by default, but I tend to change it so that all paths are relative to my code file rather than application root, using ".." eg. "../images/logos" etc
I have made a program to download an image automatically. I pass the html code ,I see the SRC attribute of the IMG html element is not the exact image file url ,it is like the following:
<img id="door2img" width="450" height="50"
src="/pincode/pin1.php?lang=zh&r=1309587154480&rule">
It is confusing, I am using c# webcontrol for programming. I can get the img html element,how can I dowload the image in such a situation,because there's not the image url?
Extract the value of the src attribute and append it to the base url (i.e. in http://some.site.com/section/page?id=5 the base url would be http://some.site.com). Pass that string to WebClient.DownloadFile or WebClient.DownloadData and you'll get what you need.
Why can't I redirect page to a image for example:
Response.Redirect("http://www.domain.com/images/image.gif");
This doesn't show me the image. Also placing conten type image/gif doesn't show the image.
Works for me. I created an "images" folder and added the following to the Page_Load method of my Default.aspx page:
Response.Redirect("~/images/scenery.jpg");
try relative path, not a complete url
meaning Response.Redirect("images/image.gif");