I have site which was mainly designed for full flash with SWFAddress, therefore all links end up with hash "#" sign (eg.: www.site.com/#/folder/image.jpg).
I want to switch flash to full HTML and don't make any of the links dead (as I left a lot of links around the web), so I created htaccess file to control the incomming requests.
The problem was with the hash "#" sign because it couldn't be handled by htaccess file. I made a piece of javascript code on top of my first index.php.
So, before I load any controller, the index.php file starts with javascript to remove hash sign and redirect back to the site without "#" i n url :
<script type="text/javascript">
var link = location.href;
m = removeHash(link);
if (link != m) {
document.location.href = m;
}
function removeHash(l) {
var unhashedUrl = l;
if (l.indexOf("#") > -1) {
var url_pieces = l.split('/');
var request = url_pieces[url_pieces.length-1];
if(request.indexOf("#") == -1 && request.toLowerCase().indexOf(".jpg") > -1){
unhashedUrl = l.replace('#', "gallery");
}else{
unhashedUrl = l.replace('#/', "");
}
}
return unhashedUrl;
}
</script>
Then all php stuff begins...
Chrome, firefox, Opera, Safari, mobile browsers... They all works flawlessly. But again the IE (tested IE8 and IE9) end up crazy. It looks like IE won't fire any JS later on. Of course when I remove JS from index controller IE works good too.
Any advice how should I achieve this?
Related
I need to get the current web page url in a single variable like:
var x = window.location.href;
But the problem is the script will be used sometimes in Cross domain Iframe & sometimes in same domain. Since window.location.href does not work in Cross domain iframe, so I have tested
x = document.referrer for cross domain Iframe(read only) and it worked fine. But I need both option in a single variable so I can use it in url validation with .match() method in Javascript.
I tried to combine like this, but its not working
var x = window.location.href;
if (typeof(window.location.href) === 'undefined') {
x = document.referrer;
}
My full codes are here:
// Get the url-This part isn't working
var x = window.location.href;
if (typeof(window.location.href) === 'undefined') {
x = document.referrer;
}
// Url validation--This part is working fine
var y = "zebra";
var rgxp = new RegExp(y, "gi");
if (x.match(rgxp) > -1) {
alert('Found a zebra in url');
I don't know is it really possible to combine or not, but otherwise I think I have to repeat this script twice. 1 for cross domain Iframe & a 2nd for the same domain.
I am fairly new in Javascript & got stuck here, so any help and direction would be a lifesaver
Javascript ain't working for me ;-(
function myFunction() {
var url = document.getElementById("value1").value;
document.write(url.split('?')[0]);
window.location = 'http://example.com/?s='+ url.split('?')[0];
}
value1 = https://www.xxxxxxxxx.com/nl/p/yyyyyyyyyyyyyy/9200000056577975/?suggestionType=browse
i only need the stuff before the questionmark (https://www.xxxxxxxxx.com/nl/p/yyyyyyyyyyyyyy/9200000056577975/)
it is working on PC (IE, Opera,...), but it ain't on iPad (safari)
I get this on ipad: https://www.xxxxxxxxx.com/nl/p/yyyyyyyyyyyyyy/9200000056577975/suggestionType=browse
What is wrong?
update:
I have added some code:
function myFunction() {
var url = document.getElementById("value1").value;
document.write(url.split('?')[0]);
url = url.replace(/%2F/g,'/');
url = url.replace(/%3A/g,'/');
url = url.replace(/%3F/g,'?');
window.location = 'http://example.com/?s=' + url.split('?')[0];
}
it is working but safari is screwing up the urls that are added. Input box is used for urls. on PC all working as it should. the .replace are used to try edit the submitted urls but ain't working. Safari document.write still shows the right urls without the %2F and %3A .
I am currently facing issue with JS and IE compatibility.
I applied a new function in my webap in its JS part its working fine in IE11,Firefox and chrome but when the user access the site using IE9 some code wont work.
is there a way to fix this ?
I am always redirected to a blank page
Ive also tried using .replace and .assign and even
var url = 'link'
$(location).attr('href', url);
Ive already place a tag in my htm but still not working:
Any help or suggestion will be highly appreciated.
<meta http-equiv="X-UA-Compatible" content="IE9">
JS
$scope.isVerify = function ()
{
if (UserLevel == '0010')
{
window.location.href = 'mailto:?subject='' + '&body='';
return false;
}
else {
$window.location.href = $scope.details.(returntoprevpage)
}
};
As per checking the issue is not on the windows.location it appears that the issue we on the email body which pass the allowable length on IE9
I am able to create a work around using iframe
I'm using jquery to rewrite a list of links on the page. If the location.host is NOT the vendor location.host AND the cookie isn't set to a specific value then it locates the links and rewrites them to the alternate values. The code I'm using works great in FF but not in IE7. Please help!
<script type="text/javascript">
// link hider
var hostadd = location.host;
var vendor = '172.29.132.34';
var localaccess = 'internal.na.internal.com';
var unlock = 'http://internal.na.internal.com/Learning/Customer_Care/navigation/newhire.html';
// link rewriter
$(document).ready (
function style_switcher(){
//if not a vendor or not accessing from lms reroute user to lms
if (hostadd != vendor && $.cookie("unlockCookie") != unlock){
var linkData = {
"https://www.somesite.com": "https://internalsite.com/something",'../Compliance/something/index.html':'../somethingelse.html'
};
$("a").each(function() {
var link = this.getAttribute("href"); // use getAttribute to get what was actualy in the page, perhaps not fully qualified
if (linkData[link]) {
this.href = linkData[link];
}
});
}
});
</script>
What you could do, if you insert the links dynamic, is store them in a data attribute like data-orglink="yourlink" which wouldnt be transformed by the browser, then check on that -and if its in the object array - change the href. Do you have access to creating the data attribute?
IE7 have problems with internal links, because it puts the host info on, before JS can reach the link..
http://jsfiddle.net/Cvj8C/9/
Will work in all, but IE7. So you need to use full paths if to use JS for this function :(
You had some errors in your JS.
But it seems to work fine?
See: http://jsfiddle.net/s4XmP/
or am i missing something? :)
As far as I know, if you want to load JavaScript or CSS files together with a specific page that is automatically loaded via ajax then you have to put the CSS/JavaScript references within the <div data-role="page"> container.
Example:
<div data-role="page" data-theme="e">
<script type="text/javascript" src="/js/jquery/plugins/plugins.js"></script>
In general, this works fine. However, somewhere along the way, the script url gets modified:
/js/some_sepcial_script.js becomes e.g. js/some_sepcial_script.js?_=1299308309681
Where 1299308309681 is the current Unix timestamp which changes on every request and thus prevents caching. I am pretty sure that this is intended behaviour but does anyone know how you can prevent the timestamp from being appended to the script/CSS urls if you want to make the file cacheable?
Have you tried:?
$.ajax ({
// Disable caching of AJAX response */
cache: false
});
It should globally change ajax requests. I'm just not sure about external scripts.
[EDIT]
This is the source code involved for jquery mobile 1.0a3:
var all = $("<div></div>");
//workaround to allow scripts to execute when included in page divs
all.get(0).innerHTML = html;
to = all.find('[data-role="page"], [data-role="dialog"]').first();
//rewrite src and href attrs to use a base url
if( !$.support.dynamicBaseTag ){
var newPath = path.get( fileUrl );
to.find('[src],link[href]').each(function(){
var thisAttr = $(this).is('[href]') ? 'href' : 'src',
thisUrl = $(this).attr(thisAttr);
//if full path exists and is same, chop it - helps IE out
thisUrl.replace( location.protocol + '//' + location.host + location.pathname, '' );
if( !/^(\w+:|#|\/)/.test(thisUrl) ){
$(this).attr(thisAttr, newPath + thisUrl);
}
});
}
Nothing on there adds a cache preventing param.
[EDIT 2]
I know this goes beyond troubleshooting to a work around but have you tried dynamically loading the js like explained here: http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml
(I know it can be done through jQuery but for testing purposes I'm trying to avoid jQuery)
if I include jQuery 1.4.3 instead of 1.5 everything works fine. That's a sufficient solution for me. Thanks again for your support.
Try running:
$.ajaxPrefilter("script", function (s) {
if (s.cache === undefined) {
s.cache = true;
}
});
Does it change this behavior?