Note that there are some explanatory texts on larger screens.

plurals
  1. POurl.content(...) like method in jquery or javascript?
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/2235979/url-helper-in-java-script">Url helper in java script</a> </p> </blockquote> <p>Url.Content(...) asp.net mvc helper method returns equivalent absolute URL. I'm searching for a method in jquery or javascript that works like this...</p> <p>because, I want to separat javascript code into a file (.js) and you know that file doesn't supports Url.Content(...) inside javscript code....</p> <p>url(...) method of jquery not works like Url.Content()</p> <p><strong>Updated: 22 Jan 2011</strong></p> <p>Hi guys, I’ve a workaround:</p> <p>In the .cshtml file, I created a ‘<strong>GetPath</strong>’ function that returns absolute path including domain name and can be accessible inside any .js file. Include following code in any ASP.NET MVC view (.cshtml or .aspx or .vbhtml):</p> <pre><code>&lt;script type="text/javascript"&gt; var fullPath = '@HttpContext.Current.Request.Url.Scheme://@HttpContext.Current.Request.Url.Authority'; function GetPath(url) { return fullPath + url; } &lt;/script&gt; &lt;script src="@Url.Content("~/JavaScriptFile.js")" type="text/javascript"&gt;&lt;/script&gt; </code></pre> <p>And the code inside any javascript file.</p> <pre><code>$(function () { alert(GetPath('/Content/Site.css')); }); </code></pre> <p>The result is: <a href="http://www.yourDomain.com/Content/Site.css" rel="nofollow noreferrer">http://www.yourDomain.com/Content/Site.css</a> or localhost:1234/Content/Site.css >> Visual Cassini server</p> <p>You just need to replace <code>@Url.Content("")</code> with <code>GetPath('')</code> in any .js file...</p> <p><a href="http://muaz-khan.blogspot.com/2012/02/absolute-or-relative-url-issues-and.html" rel="nofollow noreferrer">http://muaz-khan.blogspot.com/2012/02/absolute-or-relative-url-issues-and.html</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload