...

View Full Version : Can I use a wildcard for this?



dan18088
04-15-2005, 09:26 AM
It is not always default.aspx but is always *.aspx

var link = location.href

var regEx = new RegExp ('default.aspx', 'gi') ;

settingslink = link.replace(regEx, '_layouts/Intranet/settings.aspx')

martin_narg
04-15-2005, 05:17 PM
Not quite sure what you mean mate but this will grab the domain and pop your folder/file afterwards:


<script>
function settingsLink() {
var strSettingFolderAndFile = "/_layouts/Intranet/settings.aspx";
var rExp = /http\:\/\/(.*)\/(.*)/i;
var strSettingsLink = document.location.href.replace(rExp, "http://$1" + strSettingFolderAndFile);
//var strTest = document.location.href.replace(rExp, "Domain: $1\nFolder (if file is in a folder) and file: $2);
alert( strSettingsLink );
}
</script>


Hope this helps, I've left in strTest so you can see what the regular expression is bringing out of the document.location.href string.

m_n

dan18088
04-15-2005, 10:32 PM
I have a custom top navigation bar at the top of my Intranet and it loads menu options based on what you put in the menu_data.js file. The problem is SharePoint (A MS Portal App) which has 3 links for site settings and on the standard microsoft navbar, it knows if the is http://sharepoint/sites/maketing or http://sharepoint/sites/marketing/projects or even http://sharepoint/sites/sales (the file name is something .aspx) so if I could find *.aspx and replace it with the current url the user is at....that would be great! I was using the below code and it worked great until I realized that not all pages are called default.aspx

<html>
<head>
<script>
var link = location.href

var regEx = new RegExp ('default.aspx', 'gi') ;

link = link.replace(regEx, '_layouts/1033/settings.aspx')

document.write(link)

</script>
</head>
</html>

martin_narg
04-22-2005, 10:44 AM
Aaaah my bad - apologies.

This single line should sort you out:


var strLink = location.href.replace(/\/*\.aspx/gi, '/_layouts/1033/settings.aspx');


Hope this is right for you. It matches a / then any number of characters (the *) then .aspx and replaces with /_layouts/1033/settings.aspx

m_n

dan18088
04-22-2005, 11:02 AM
That should work just fine.

Dan



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum