Programming, SharePoint, Web

SOLVED: Redirect a SharePoint page using a meta tag to a new URL

I have a SharePoint tenant where we are working to redirect some existing pages over to landing pages that are providing instructions for migrating. Needed something short and sweet to flip it over without much trouble. It’s easier to manage with a meta rather than fighting the “making your external client side javascript work with SharePoint” fight. This one takes less than 5 minutes.

So via SharePoint Designer:

<meta http-equiv="refresh" content="0;url=http://your-url-goes-here" />

That’s it. Onto the next one!

HTML, JavaScript, Troubleshooting, Web

Check For Internet Explorer (IE) Compatibility Mode

Create a JavaScript file called iecheck.js and paste the following in the snippet:

function trueOrFalse() {
 return true;
}

function IeVersion() {
 // Set defaults
 var value = {
 IsIE: false,
 TrueVersion: 0,
 ActingVersion: 0,
 CompatibilityMode: false
 };

// Try to find the Trident version number
 var trident = navigator.userAgent.match(/Trident\/(\d+)/);
 if (trident) {
 value.IsIE = true;
 //Convert from the Trident version number to the IE version number
 value.TrueVersion = parseInt(trident[1], 10) + 4;
 }

// Try to find the MSIE number
 var msie = navigator.userAgent.match(/MSIE (\d+)/);
 if (msie) {
 value.IsIE = true;
 // Find the IE version number from the user agent string
 value.ActingVersion = parseInt(msie[1]);
 } else {
 // Must be IE 11 in "edge" mode
 value.ActingVersion = value.TrueVersion;
 }

// If we have both a Trident and MSIE version number, see if they're different
 if (value.IsIE &amp;&amp; value.TrueVersion &gt; 0 &amp;&amp; value.ActingVersion &gt; 0) {
 // In compatibility mode if the trident number doesn't match up with the MSIE number
 value.CompatibilityMode = value.TrueVersion != value.ActingVersion;
 }
 return value;
}

Once you have the JavaScript file then open your page where you are going to check for compatibility for and place a reference to the iecheck.js file in the head tag.

<script src="iecheck.js" type="text/javascript"></script>

After that you have multiple options on how to use the script.

For example, if you would like to check for compatibility and redirect then paste the following snippet inside of the body of your html:

<script type="text/javascript">
// 0 = not in compatibility view, 1 = in compatibility view
var ie = IeVersion();
if ((ie.CompatibilityMode == "0") && (ie.IsIE == "1")) {
window.location = "redirecttosomewhere.html"
}
else {
// do nothing, is in compatibility view
}
</script>

Another example would be if you just want to see the results on the page; just place this snippet inside of the body of your html:


<script type="text/javascript">
// <![CDATA[
var ie = IeVersion();
document.write("IsIE: " + ie.IsIE + "</br>");
document.write("TrueVersion: " + ie.TrueVersion + "</br>");
document.write("ActingVersion: " + ie.ActingVersion + "</br>");
document.write("CompatibilityMode: " + ie.CompatibilityMode + "</br>");
// ]]>
</script>

Hope this helps. Questions are always welcome.

HTML, JavaScript, Web

JavaScript HTML Redirect To Another URL

There may be cases where you don’t have as free of access to the meta information or web.config to set redirects in place. You can also do this with JavaScript!

Here’s the snippet (place this in between script tags in the body or applicable section in the body that allows HTML):

<script type="text/javascript">
    window.location.replace("http://www.yourexamplesite.com/some-other-page.html");
</script>

Hope that helps.

HTML, JavaScript, Uncategorized, Web

How To Detect The Edge Browser And Redirect To Another Page In JavaScript

There will likely be cases where you have sites that were built for IE but are not caught up to Edge yet. What do you do in the interim? One idea that I applied on a legacy site was to inform take the Edge user to a specific page. You can always do a multitude of things when dealing with how to address the user (alerts, redirects, updates to labels on pages, etc.). I just want to show an easy way to detect and redirect.

The first thing you need to know is the Edge Browser’s User Agent String:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.9600

You can take advantage of the navigator.userAgent property in JavaScript and do a quick check of it. In this example I check for “Edge” and redirect if it is contained in the string.

Place the following in a script tag inside of the head section of your html:

<script type="text/javascript">
var ver = navigator.userAgent;
if (ver.indexOf('Edge') !== -1)
{
window.location = "https://www.afakewebsite.com/edgemessage.html";
}
else
{
// Not Edge, do nothing
}
</script>

Hope it helps.

Classic ASP, Web

Check For A Referring Page URL And Redirect (Classic ASP)

I spent a while looking around for something that would help me tighten up some pages that did not need reached unless they came from another page that I had authorized.

In this example we check first that there is a referring URL and if there is not then go to my error page. The next part two checks look to ensure that the referring page is not the two pages we are okay with the referring URL to be.  If the referring URL is not either of those then we know the previous page is not what we want either and we refer to an error page.

<%
referer=request.servervariables("http_referer")
if (referer = "") then
Response.Redirect "error.asp"
elseif (referer <> "<a href="https://www.google.com">https://www.google.com</a>") then

elseif (referer <> "<a href="https://www.yahoo.com">https://www.yahoo.com</a>") then

else
Response.Redirect "error.asp"
end if
%>