Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Razor CSS file location as Variable

I am wrapping a razor view in an iframe. The razor view is a web service on a different domain.

Here is what I am doing:

<!DOCTYPE html>
<html>
<body>

<p align="center">
    <img src="http://somewhere.com/images/double2.jpg" />
</p>

<p align="center">
<iframe src="https://secure.somewhereelse.com/MyPortal?CorpID=12334D-4C12-450D-ACB1-7372B9D17C22" width="550" height="600" style="float:middle">
  <p>Your browser does not support iframes.</p>
</iframe>
</p>
</body>
</html>

This is the header of the src site:

<!DOCTYPE html>
<html>
<head>
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/themes/cupertino/jquery-ui-1.8.21.custom.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
</head>

I want the iframe src to use the CSS of the calling site.

Is there a way to pass in the CSS URL or have it inherit the CSS of the calling site?

I'd even settle for the css file location being a parameter being passed in from the originating site.

Anyone have any suggestions?

like image 860
ErocM Avatar asked Aug 03 '12 16:08

ErocM


People also ask

How do I reference a CSS file on a Razor view?

All you have to do is to place a style sheet in the Pages folder alongside the page that it is intended to affect. You just need to follow a specific naming convention, which is the Razor page file name with . css on the end. The bundled file itself is placed in the wwwroot folder when the application is published.

Where do I put CSS variables?

First of all: CSS variables can have a global or local scope. Global variables can be accessed/used through the entire document, while local variables can be used only inside the selector where it is declared. To create a variable with global scope, declare it inside the :root selector.

How do I declare a variable in CSS file?

CSS variables are custom variables that you can create and reuse throughout your stylesheet. Here is the basic syntax for defining a custom CSS variable. --css-variable-name: css property value; If you want to access that variable, then you would use the var() function.

Can CSS store variables?

CSS variables are custom properties in which you can store a value and use it anywhere in the HTML code.


2 Answers

You cannot enforce your css on your site using an iframe. The css must be included in the source of the page included in an iframe. It used to be possible but in certain cases using javascript, and for the page to be on the same domain.

The only other way you may be able to use your own css is if the web service allows you to pass in the url of the css. But you would have to consult the documentation of the web service to find that out.

like image 199
James Williams Avatar answered Oct 12 '22 02:10

James Williams


I would pass the CSS url as an argument to the iframe's src attribute:

<iframe src="http://somedomain.com/?styleUrl=@(ResolveStyleUrl())"></iframe>

Where ResolveStyleUrl might be defined as:

@functions {

  public IHtmlString ResolveStyleUrl()
  {
    string url = Url.Content("~/Content/site.css");
    string host = "http" + (Request.IsSecureConnection ? "s" : "") + "//" + Request.Url.Host + url;
    return Raw(url);
  }

}

This is of course assuming that the domain would accept a style url query string and render the appropriate <link /> on the remote page?

like image 42
Matthew Abbott Avatar answered Oct 12 '22 03:10

Matthew Abbott