Pre-existing URLs with /# stop working - history.js

I have existing URLs that used the URL hash to provide extra data to javascript after page load, e.g.
http://www.example.com/my/directory/#/foo/bar/
I'm implementing jquery.history for something else, but also need to make those old URLs continue to work (e.g. if someone might have bookmarked it with the /#... part).
However on page load the plugin is stripping out everything between the domain and the /#, e.g. the URL ends up becoming:
http://www.example.com/foo/bar/
This isn't happening in IE 9, but is happening in Firefox and Chrome.
Any ideas? I don't consider this a bug in the plugin, but I'm happy to amend the unminified source files for my own usage, if someone suggests a fix that won't break the rest of its functionality.
One possible idea - I no longer care about what that extra data in the URL after the # is, so could perhaps remove that part from the URL before the history plugin does anything to it. I'm not entirely sure yet at what point that could be, or more specifically when the plugin is amending the URL on page load.

In the end I did what I mentioned at the end of my question. Added this bit of inline JS prior to the call to the history plugin js file:
(function(){
if (document.location.hash.length !== 0) {
document.location.hash = '';
}
})();
At worst we end up with the URL still having a trailing # at the end, but as it doesn't have #/ then the history plugin doesn't then mess it up.

Related

Absolute external links bug, url of the current page added at the beginning of the url

I have a very strange external links behavior on this page:
https://dev.switchonpaper.site/en/daniel-g-andujar-the-artist-as-a-thinker-and-augur-of-what-happens/
There is a list of external links visible by clicking on "Go Deeper".
On some links, the address of the current page is added at the beginning of the external link.
E.g.: iSAMâ„¢ (1997)
E.g.: TTTP Photo Collection - 1997
All external links are absolute links.
When you look at the source code, the links are correct.
This site runs under Wordpress, the links are contained in a Gutenberg block built with the ACF plugin.
I tested the following things:
Disable all plugins.
The browser or something else continues to add the current page address on some links only.
I emptied the server cache, removed all the .htaccess rules except the wordpress part.
I made sure that the PHP file that writes these links is in UTF-8.
By recreating the links, it is always the same ones who are affected.
Does anyone have any idea what could cause this?
Thank you for your time and help!
You have the so called "hidden characters" before your link start. I suggest you to check it by yourself with some online tool like this: https://www.soscisurvey.de/tools/view-chars.php. If you try to paste there the link copied by your source code you will see you have hidden stuff before "https:..."
The solution to this issue is that you delete all the characters and you write them all over again by yourself, w/o copy/pasting them from another source or in alternative paste them inside some non-HTML text editor before pasting them to your website

Chrome caching CSS but not loading images inside CSS file

We're having a weird problem at work that happens only in chrome. It looks like the css file is getting cached and the content of this file isn't getting re-downloaded.
The problem is that when using a fresh session for example "private session", the image "mainSprite.png" isn't getting displayed.
After some tests, I believe the problem is related to us doing redirects at the beginning if the user isn't authenticated. From what I understand, it might not complete the download of the sprites linked inside the css files. It will cache an invalid object as soon as the redirect starts and then on the following pages, it will fail to display a correct image since it cached something wrong.
The strange thing is that it actually loads the image completely at some point. But it looks like it's not refreshing it in memory...
I did a timeout of one second before starting redirects on first load and images correctly display. This is a quick fix and I can't expect every computer to load in 1 second every images contained in the css.
edit
As far as I can say, it really looks like a race condition. I changed the order of loading. We use require.js. Instead of loading js after css, I start js loading before. And images are getting loaded correctly now on my local server.
if someone is interested to look into it:
http://api.checklist.com
edit 2
When images aren't visible, opening new tabs will have the same problem. Closing the browser and reopening it will work on first load and images isn't being downloaded but loaded from Cache which means that before closing the browser, the image was indeed downloaded.
It looks like the problem coming from your redirects unfortunately i couldn't see your example ( link won't open ). Google chrome has indeed issues with caching it's annoying during development time ( clear up the cache, load new image, do the same for new image..), if you need to clear your cache try the folowing:
try to go to
chrome://chrome/settings/clearBrowserData
in your chrome browser and check the options:
Empty the Cache( i have also Clear download history and Delete cookies and other site and plug-in data )
click on 'Clear Browsing Data' button it should
All what you need to do is to trace your cash list via chrome, and from what I see is that you got this error which make it not cached:
Uncaught TypeError: Object [object Object] has no method 'placeholder'
So if you want to trace, you can use the manifest offline mode or you trace via your code.
Just following and test your page, I did catch where the error is:
file: scripts2.js Line 20 --> $('input[placeholder]').placeholder();
which you need to check the name of the place holder and change it here in this tag.
Thank you
I assume your server/backend app has routes set up. Like this Play! framework example:
# Ignore favicon requests
GET /favicon.ico 404
# Map static resources from the /app/public folder to the /public path
GET /public/ staticDir:public
# Catch all
* /{controller} {controller}.index
According your summary I suggest to set up a static folder route (where the images are) in config file or htaccess as you want, then check image url in browser url bar (with empty session). That should work!
First I would suggest that you first try to find ways to narrow the redirects. If it possible I would suggest that it would be much more advisable to try to create your content dynamically based on your users authentication using languages like PHP or ASP (just to name two).
The classic way of disabling the caching on a webpage is to set two <meta> tags inside of your <head> </head> tags. However, you should note that these are technically not "correct" as they are not part of any of the "offical" standards documentation. This also means that I would again lean towards my first suggestion of finding a better delivery system which in turn should prevent the problem.
So for "testing" purposes the tags would be:
<HEAD>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="0">
</HEAD>
Maybe I don't understand your question or dilemma (maybe because of lack of explanation or because I can't see your page at that link since I run Chrome), but there's an example I ran across here that works in Chrome by just using Javascript/jQuery to load, instead of CSS:
http://jsfiddle.net/2Cgyg/6/
Use image at URL: http://www.w3schools.com/cssref/img_tree.gif
And although the accepted answer didn't work for me in Chrome, this is the question I got the jsFiddle above, from:
Load Image from javascript
All the caching, etc. is unnecessary, and even something you wouldn't want to do if your images are ever updated to something else - they won't appear without forcing a refresh which you can only do through altering the file name like this to avoid users not seeing your updated image:
myPic.jpg?MMDDYYYY
And you could set the date according to the date you are modifying it.
clean your browser history like cache,cookies
clean the temporary internet file
if problem not solved then reinstall browser your problem is solved definitely

Session Variables not working firefox and Wordpress

ok this is desperation, I have tried every fix I can find but with no luck.
I am using session variables in wordpress and it works fine in every browser except for Firefox. I have cleared the cache, cookies, started in safe mode etc but no joy. Cookies are enabled and I have also tried it on different pc's.
I start the session in my theme functions file as follows:
function myStartSession() {
if(!session_id()) {
session_start();
}
}
add_action('init', 'myStartSession', 1);
Then on my individual page templates I create the session variable as follows:
$_SESSION['hq'] = 1;
I can confirm that the sessionid remains unchanged in every browser and is working correctly including Firefox, however in FF the session variable is not correctly passed from one page to another and the results are unpredictable.
Any solutions / recommendations are very welcome.
Not a brand new question, but since I was looking for a solution and got here, I'll answer it to maybe help other programmers.
I had a similar problem with a WordPress theme that I developed and I found a solution in this post at StackExchange: https://wordpress.stackexchange.com/questions/40271/2-different-post-ids-for-single-page-load-only-in-firefox
Due to Firefox's prefetch, the next post/page is loaded in background and session is affected by this behavior.
There is at least two possible solutions to fix this:
Remove the action that inserts the next page/post in page <head> with the following function call:
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
It can be added to your theme's functions.php file.
Check the request headers to handle (or maybe ignore) prefetching. All prefetching requests are sent to the server with a special header, as follows:
X-moz: prefetch
You can look for this header and treat the request in a distinct way.

Problem passing parameters via Iframe in IE

I'm trying to execute an HTTP GET from my website to another website that is brought in via iframe.
On Firefox, you can see in the source that the correct url is in the iframe src along with it's correct parameters-- and it works.
On IE, you can see in the source that the correct url is in the iframe src along with it's correct parameters-- and it doesn't work...
Is there something about IE that doesn't let you pass parameters through an iframe in the querystring?
I've tried refreshing the iframe in IE, I've tried refreshing my page & the iframe in IE, and I've tried copying the url and re-pasting it into the iframe src (forcing it to refresh as if I just entered it into the address bar for that iframe window). Still no luck!
Anyone know why this is happening, or have any suggestions to try to get around this?
Edit: I cannot give a link to this because the site requires a password and login credentials to both our site and our vendor's site. Even though I could make a test account on our site, it would not do any good for the testing process because I cannot do the same for the vendor site. As for the code, all it's doing is creating the src from the backend code on page load and setting the src attribute from the back end...
//Backend code to set src
mainIframe.Attributes["src"] = srcWeJustCreated;
//Front end iframe code
<iframe id="mainIframe" runat="server" />
Edit: Problem was never solved. Answer auto accepted because the bounty expired. I will re-ask this question with more info and a link to the page when our site is closer to going live.
Thanks,
Matt
By the default security settings in IE query parameters are blocked in Iframes. On the security tab under internet options set your security level to low. If this fixes your problem then you know that is your issue. If the site is for external customers then expecting them to turn down their security settings is probably unreasonable, so you may have to find a work around.
Let's say your site is www.acme.com and the iframe source is at www.myvendor.com.
IIRC, most domain-level security settings don't care about the hostname, so add a DNS CNAME to your zone file for myvendor.acme.com, pointed back to www.myvendor.com. Then, in your IFRAME, set the source using your hostname alias.
Another solution might be to have your Javascript set the src to a redirector script on your own server (and, thus, within your domain). Your script would then simply redirect the IFRAME to the "correct" URL with the same parameters.
If it suits you, you can communicate between sites with fragment identifiers. You can find an article here: http://tagneto.blogspot.com/2006/06/cross-domain-frame-communication-with.html
What BYK said. I think what's happening is you are GETting a URL that is too large for IE to handle. I notice you are trying to send variable named src, which is probably very long, over 4k. I ran into this problem before, and this was my code. Notice the comment about IE. Also notice it causes a problem with Firefox then, which is addressed in another comment.
var autoSaveFrame = window.frames['autosave'];
// try to create a temp form object to submit via post, as sending the browser to a very very long URL causes problems for the server and in IE with GET requests.
var host = document.location.host;
var protocol = document.location.protocol;
// Create a form
var f = autoSaveFrame.document.createElement("form");
// Add it to the document body
autoSaveFrame.document.body.appendChild(f);
// Add action and method attributes
f.action = protocol + '//' + host + "/autosave.php"; // firefox requires a COMPLETE url for some reason! Less a cryptic error results!
f.method = "POST"
var postInput = autoSaveFrame.document.createElement('input');
postInput.type = 'text'
postInput.name = 'post';
postInput.value = post;
f.appendChild(postInput);
//alert(f.elements['post'].value.length);
// Call the form's submit method
f.submit();
Based on Mike's answer, the easiest solution in your case would be to use "parameter hiding" to convert all GET parameters into a single URL.
The most scalable way would be for each 'folder' in the URL to consist of the parameter, then a comma, then the value. For example you would use these URLs in your app:
http://example.com/app/param,value/otherparam,othervalue
http://example.com/app/param,value/thirdparam,value3
Which would be the equivalent of these:
http://example.com/app?param=value&otherparam=othervalue
http://example.com/app?param=value&thirdparam=value3
This is pretty easy on Apache with .htaccess, but it looks like you're using IIS so I'll leave it up to you to research the exact implementation.
EDIT: just came back to this and realised it wouldn't be possible for you to implement the above on a different domain if you don't own it :p However, you can do it server-side like this:
Set up the above parameter-hiding on your own server as a special script (might not be necessary if IE doesn't mind GET from the same server).
In Javascript, build the static-looking URL from the various parameters.
Have the script on your server use the parameters and read the external URL and output it, i.e. get the content server-side. This question may help you with that.
So your iframe URL would be:
http://yoursite.com/app/param,value/otherparam,othervalue
And that page would read and display the URL:
http://externalsite.com/app?param=value&otherparam=othervalue
Try using an indirect method. Create a FORM. Set its action parameter to the base url you want to navigate. Set its method to POST. Set its target to your iframe and then create the necessary parameters as hidden inputs. Finally, submit the form. It should work since it works with POST.

page loads twice in Google chrome

Does anyone have any problems with Page_Load being executed twice in Google Chrome?
It's a short question, i do not know what else to explain...
I have a simple asp.net page and in Firefox and IE all it's working fine.
But in Chrome the Page_Load is fired twice...
Anyone has any ideas why?
Later EDIT:
- what is strange is that i have 4 repeaters... binded with random values. The random methods are twice fired (because of page loaded twice) but the repeaters takes the INITIALLY values...so, the 2nd post back is somehow raised after the rendering step.
3rd edit: It happens ONLY at the refresh!
Solution (in my case): There was an empty img src, and that was the cause
I notice this same issue in IE if the page contains img tags that don't have a src attribute (or the src is empty, etc). Not sure if Chrome does the same thing, but worth checking, right?
For me the problem was because of the extension Firebug Lite for Google Chrome. Once deactivated the page only loads once.
I had a very similar problem:
Chrome and Firefox loading the page twice,
Internet Explorer loading it once.
The problem was because of my .htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
When the browsers were requesting a favicon.ico, my index.php page was called, thus creating a double access to the server.
My solution was to create a favicon.ico, although I could also had index.php handle that special case, or even .htaccess, but I needed a favicon.ico anyway :)
I had the same stupid problem.
Page loads twice and the updates went blank.
Thanks to this posting I checked my CSS sheet.
I removed this line:
body {
background-image: url();
}
That was the problem
I recently had this issue with Chrome rendering twice too, the cause of this issue is
<iframe src="#"></iframe>
once I set it to
<iframe></iframe>
or completely remove iframe then the double rendering no longer appears.
In addition to Chris Shaffer's answer which got me on the right track, I'd like to add that in my case there was also a <script> tag with an empty src that caused the problem.
Perhaps it applies to all elements with an empty src.
Gecko based browsers apparently do this when the markup is incorrect. That means XHTML AND CSS.
Here is a great post about the issue: http://www.110mb.com/forum/how-to-stop-firefox-dual-pageloads-t27704.0.html
That's why some of you guys are getting the problem when you have a blank src attribute or a blank href attribute. Incorrect syntax, the browser reads it as an "error". I guess it's a more unobtrusive type of error that you would otherwise not even notice, but due to the nature of the page you're working on it's become apparent and presented itself as a rather obtrusive problem.
What certain browsers consider to be an 'error' and what is 'passable' is probably slightly different too, that would explain why some of you are having the problem in FF and not in Chrome and visa versa.
Just be thankful you're not in my shoes. I've got a page that's sending an email out twice due to this issue and there's no way I can fix the bad markup because there's just simply too much of it to fix being generated in far too many places, a lot of the CSS and HTML issues are dynamically driven too unfortunately.
I still don't understand the reasoning behind it grabbing the page twice though when it encounters non-compliant issues of this nature though.
This may be a problem with one of the extensions/plugins. Try out the incognito mode - this helped me once.
Base on Johann's reply, I check and disable each extension in google chrome and discover the flash extension cause my browser reload twice. After remove it, the problem is solved!!
In my case it was this <link rel="shortcut icon" href="#" /> tag in the head of my index.html file:
<html lang="en">
<head>
...
<link rel="shortcut icon" href="#" />
...
</head>
...
</html>
I just removed that line and problem solved.
So far I've used Chrome to test ASP.NET pages many times and never encountered this. What are you doing client-side that could cause this? Are you doing any AJAX stuff?
I noticed that this started happening to me when I switched to Chrome v.4, the developer's channel, so that i could start using extensions. Didn't seem to be a problem with v.3, the stable version.
In your Page_Load, check the value of Page.IsPostBack and Page.IsCallback to see if they differ between the two calls. If they're different, it could be some javascript reexecuting or chrome following a redirect twice or something odd like that.
I encountered a similar problem with PHP and Firefox.
The problem was coming from a faulty style definition that Firefox interpreted to reload the page.
I cannot remember exactly what it was but int the idea, could be something like
.my_class { background: url(#); }
I would advice to try to isolate first your CSS and then your HTML sections to check if the problem might come from it.
If you set your image tag src to # or empty it will cause twice pageload calling, i faced this on chrome and before on firefox.
you can put any char or string value instead of empty or # to solve this issue.
It also doesnt like empty href's
I had an empty favicon link tag and it did the same thing. Whoever said about the empty src put me onto that, just stripped out everything until it started working
I'm also having this issue.
Funny, I added "visible=false" to the whole "form" tag making the page totally empty - it still loads twice. I also tweaked the DOCTYPE, checked the img-tags for empty sources etc. etc. etc.
It still loads twice.
BUT I noticed that this happens on "localhost" only. Remote websites work fine.
I thought may be is has something to do with DNS, but "127.0.0.1" also loads twice. This drives me nuts...
Ran into the same issue. I was using DOM Snitch.
I disabled it and it immediately stopped posting back twice.
After looking at it, it seems to contain 2 tags without an href attribute. Because it's a Chrome extension it's injected into the DOM at the client and I suppose this causes a Webforms page to post back twice.
On the off chance someone sees this, be sure to check any extensions and/or plugins you are using.
I had the same issue. However my "mistake" was located in my css file.
I was using .htaccess to rewrite everything back to my root folder but used
background-image: url('../img/login_facebook.png')
in my css file. I removed the .. and the problem was solved.
Here is another great article on why this occurs: https://www.nczonline.net/blog/2009/11/30/empty-image-src-can-destroy-your-site/
I was getting the same error using Chrome in an ASP.NET site. I was getting the page life-cycle firing again with IsPostBack set to False.
This caused all sorts of issues for me.
I just had the same issue, and once I shut down the JSON Viewer extension, problem was solved.
I can recommend this extension for viewing JSON's without the extra request as side-effect:
https://chrome.google.com/webstore/detail/json-formatter/bcjindcccaagfpapjjmafapmmgkkhgoa
I believe it is just how Google Chrome works. I put some code on my index page to write to a file with the file name that was loaded, and every time I load the page (using refresh or a new window) it puts 2 results in the file.
EDIT: I renamed my index file to test.php and ran it again. This time it only had one result. This problem is pissing me off.
EDIT: I renamed my file back to index.php and ran it. Same problem. Then I renamed my .htaccess (for mod_rewrite) to htaccess so it wouldn't be parsed and the problem is gone. After I found this out, I disabled url rewriting in the .htaccess file and the problem was still gone (finally). I did one more test (if people are still reading this crap) and found that google loads the page twice when you redirect from the .htaccess file. I found a little workaround that seems to fix the problem.
Not sure if this applies to asp.net. I only know php coding and apache servers.

Resources