I'm having a strange behavior and I'm fighting with myself in order to figure out what error can be.
I have an HTML page that, on body load, checks for the presence of a Variable "TRANSACTIONVALUE" in query string.
If the string is present and has specific value (8374), user is redirected to a specific page (let's call it "backend page").
Due that sometimes this "backend page" is a bit slow (it fires an agent that sometimes goes down for inactivity, so need to wait to reactivate it), i resolved it just adding a document.write that says just "Request in course... Please wait" in the same blanked page before the redirect.
My code is working for ALL browser, except for Internet Explorer where users are blocked in the first statement "document.write".
<!doctype html>
<html lang="us">
<head>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="TEXT/HTML;CHARSET=UTF-8">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="-1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../../../favicon.ico">
<script>
function CheckHeaderStatus() {
if (getQueryVariable("TRANSACTIONVALUE")==8374)
{
document.write("Request in course... Please wait");
window.location.href='http://backendapplication.goto.com/Default.aspx?TARGET='+TRANSACTIONVALUE;
}
}
</script>
</head>
<body onload="CheckHeaderStatus()" class="text-center">
<div> any text <div>
</body>
</html>
What happens is that it works for Chrome, Safari, Firefox. In these cases if an user has the TRANSACTIONVALUE=8374, on body load he can see the "Request in course... Please wait" message and then is redirect to the page http://backendapplication.goto.com/Default.aspx?TARGET='+TRANSACTIONVALUE
Now, in Internet Explorer users with TRANSACTIONVALUE=8374 can see ONLY the "Request in course... Please wait" message. The page stop to go head and so they are not redirect to the other page.
What can be the problem?
I have tested other way to obtain the same (as proven of my work) like:
"Remove all content from the page, create a div where I can write the massage of waiting, and then redirect, so:
while (document.firstChild) {
document.removeChild(document.firstChild);
};
// create new DIV
var newDiv = document.createElement("div");
newDiv.innerHTML = "<h1>Request in course... Please wait</h1>";
window.location.href='http://backendapplication.goto.com/Default.aspx?TARGET='+TRANSACTIONVALUE;
but again, it works for all browser expect for IE. I tested with IE9,10,11.
I'm missing something or it is a problem of IE?
Thanks all!!!
I have resolved in this way:
function CheckHeaderStatus() {
if (getQueryVariable("TRANSACTIONVALUE")==8374)
{
Redirect();
function Redirect() {
document.write("Request in course... Please wait");
window.location.href='http://backendapplication.goto.com/Default.aspx?TARGET='+TRANSACTIONVALUE;
}
}}
In this way it works also for IE :-)
Related
Below is my piece of code that work's in all the browser in all the OS, except ipad chrome. Help me out here.
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<script>
function myprint() {
const wnd = window.open('about:blank', '', '_blank, alwaysRaised=yes');
wnd.document.write('<html><head><title></title>');
wnd.document.write('</head><body>');
wnd.document.write('<div>JavaScript often abbreviated as JS, is a high-level, interpreted programming language. It is a language which is also characterized as dynamic, weakly typed, prototype-based and multi-paradigm.</div>');
wnd.document.write('<div class="print-header"><button title="Print" onclick="window.print()">Print</button></div>');
wnd.document.write('</body></html>');
wnd.document.close();
}
</script>
<body>
<button onclick="myprint()">popup</button>
</body>
</html>
Here Im trying to open my content using window.open() then print them using window.print(). That's all. jsfiddle
This link also not working in ipad chrome.
Print
This is an issue with Chrome on iOS. Because of Apple’s policy on third party browsers, Chrome is actually just a WebView component. Printing is currently not supported. As far as I am aware, there is currently no workaround for this issue.
Try this code, if it not works another solution is to use a third-party printing service like this: http://www.printfriendly.com
function goPrint(){
window.print();
if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
window.location.reload();
}
}
You are using a backtick character ` in this line:
wnd.document.write(`<div class="print-header"><button title="Print" onclick="window.print()">Print</button></div>`);
This is a Templated literal and might not be supported. Try replacing it with a single quote:
wnd.document.write('<div class="print-header"><button title="Print" onclick="window.print()">Print</button></div>');
This post is just to learn something, Recently I came across a domain called as www.content-queen.me/PtWkz in a page from facebook.com, on clicking the post with this link it redirected me another domain http://www.wittyfeed.com/story/18644/when-9-cops-sat-down-at-red-robin-the-waitress-realized-something-is-terribly-wrong?utm_source=undefined&utm_medium=SOCIAL&utm_campaign=33-campaign&utm_hash=PtWkz&i=2...Initially I dint see it, but the next time I did with another url, the same thing happened..so my question is how to do it, I know how create a redirect, as it can be done in .htaccess, but this kind of redirect is very new and interesting, And I even tried to dissect the code and found this source code
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta charset="UTF-8">
<title>When 9 Cops Sat Down At Red Robin, The Waitress Realized Something Is Terribly Wrong</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta property="og:locale" content="en_US" />
<meta property="og:type" content="article" />
<meta property="og:title" content="When 9 Cops Sat Down At Red Robin, The Waitress Realized Something Is Terribly Wrong" />
<meta property="og:description" content="You never know when any deed done by you can make anyone's day. Hence, being on the good side of the threshold is always preferable. Jessica Dunbar definitely understands the effect good actions have and she is definitely doing everything the right way. Especially, when it is about men in uniform. When she notices a group of cops sitting in her section, this happens." />
<meta property="og:url" content="http://www.content-queen.me/PtWkz" />
<meta property="og:image" content="http://cdn.wf-media.com/18644/pvoaelaw7buvswooe47x.jpeg" />
<meta property="og:site_name" content="www.content-queen.me" />
<meta property="article:section" content="Pictures" />
<a href="https://www.viral9.com/tr_hs_vs/PtWkz" id='myLink'></a>
<style type="text/css">
#myLink {
display: none;
}
</style>
</head>
<body>
<div id="output">
</div>
</body>
</html>
<script type="text/javascript">
// view_count_update();
function view_count_update()
{
var jUTM = "utm_source=SOURCE&utm_medium=referral&utm_campaign=CAMPAIGN&utm_hash=HASH";
var redirect_url = "http://www.wittyfeed.com/story/18644/when-9-cops-sat-down-at-red-robin-the-waitress-realized-something-is-terribly-wrong?utm_source=SOURCE&utm_medium=SOCIAL&utm_campaign=33-campaign&utm_hash=PtWkz&i=2";
redirect_url = redirect_url.replace("SOURCE", document.referrer.split('/')[2]);
window.location = redirect_url;
}
function myFunc(){
}
//hello
</script>
<script>
try{
(function(){
var d = {
'user_id' : "33",
'url_id' : "2609257" ,
'advertiser_id' : "1",
'user_agent' : navigator.userAgent,
'campaign_id' : "18362" ,
}
$.ajax({
url: "http://www.asapoo.com/mysql_testing",
type:'GET',
data: d,
success : function(data) {view_count_update();},
error : function(){ view_count_update();},
complete: function() {view_count_update();},
timeout : 2000
});
})();
}catch(e){ view_count_update(); }
</script>
<script src="//c.fqtag.com/tag/implement-r.js?org=T6tuwESp3TrUwruYu4eZ&p=NOTSET&a=33&cmp=PtWkz&rt=display&sl=1&fmt=banner&ctu=http%3A%2F%2Fwww.wittyfeed.com%2Fstory%2F18644%2Fwhen-9-cops-sat-down-at-red-robin-the-waitress-realized-something-is-terribly-wrong%3Futm_source%3DSOURCE%26utm_medium%3DSOCIAL%26utm_campaign%3D33-campaign%26utm_hash%3DPtWkz%26i%3D2&fq=1"></script>
I hope there will be guys who would have done this here and would like to learn how to do it.
That code is pretty much it, really. The redirects are coming from a site set up just for that. It most likely has a database driving it, mapping those random strings of letters to sites. Then it had a template for the page you posted here where it fills in values from the database.
You can see in the code where it updates a page view counter. Then, right after that it sets window.location to where they want you to go, which makes the browser load the page.
This is called a url shortener, you need a back-end script to do the redirect.
The application works as follows, when a request for www.content-queen.me/PtWkz, it will analyze the url. and take the random string PtWkz as a key, this key is connected to the orginal url and the relation stored somewhere in database or cache memory.
What the script do is to match the short string to the orginal url and send to our browser http redirect 302.
There are some feathers to the shortener like you can change the destination the original url with keep sharing the short url.
The back-end script can be written in all programing languages and scripts, you may use python or php for it.
There are many online url shortener services like goo.gl and bitly.com.
I'm no js expert but I've minimised my faulty script and tried to localise the fault without success. You can find the actual page at www.trinitywoking.org.uk. but my minimal test case is
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<title>MinTestCase</title>
<script>window.onload = function () { // Don't run script until page is loaded
var votd = new Array();
votd[129]="Mount Sinai was all smoke because God had come down on it as fire.";
// Prepare today's string for display
document.getElementById("keyverse").innerHTML="<p> " + votd[(129)] + "</p> ";
}
</script>
</head>
<body>
<h1>Target paragraph follows </h1>
<p id="keyverse">
</p>
</body>
</html>
This runs and displays correctly on all browsers except IE lte 8.
A second script runs on all browsers so it doesn't look like a permissions issue.
I'll be very grateful for any help with this.
Thanks.
Remove the <p> tags in document.getElementById() line:
document.getElementById("keyverse").innerHTML=votd[(129)];
There are already tags where you try to edit the innerHTML. IE is a very picky browser.
OK guys this is intreting,
I'm testing this page
http://static.nemesisdesign.net/demos/ie8-strange/test.html
on IE8 / windows XP.
This is the code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="content-language" content="en">
<title>Test</title>
</head>
<body>
<div id="thisgivesmeanerror">test</div>
<script>
thisgivesmeanerror = 'test';
alert('this alert won\'t be fired on my IE8, what about yours?');
</script>
</body>
</html>
If I open this page with IE8 I get an error.
If I change the code of the script to:
<script>
// note that I added var prefix
var thisgivesmeanerror = 'test';
alert('this alert won\'t be fired on my IE8, what about yours?');
</script>
It works fine.
This happens only on IE 7/8, didn't test it on IE6.
What do you think?
Does it happen to you also? Or is it just my browser that has gone crazy?
Addition
You're saying that is just not using the var prefix that cause the error?
I'm sorry guys but you're wrong, you didn't take time to test the code.
I uploaded a test2 page
http://static.nemesisdesign.net/demos/ie8-strange/test2.html
with the follwing cocde
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="content-language" content="en">
<title>Test 2</title>
</head>
<body>
<div id="thisgivesmeanerror">test</div>
<script>
thisdoesntgiveanyerror = 'test';
alert('This alert will be fired correcly');
</script>
</body>
</html>
That works fine.
So what is actually causing the error? The variable name without the var prefix having the same name as the ID of the DIV element.
Isn't this strange?
May be the answers to this SO-question can help?
You should always precede your variable declarations with var to specify their scope or you might observe inconsistent behavior between different browsers.
use var to declare variables instead of just plugging their name
I'd say the JavaScript interpreter in IE is slightly stricter than on FireFox and others, meaning the script returns an error when it comes to the variable definition line. Putting var in will ensure it actually is a variable.
It's very good practice to declare all your variables with var
James
EDIT
I can't get to IE at the moment, but I can recommend you change your <script> tag to <script type="text/javascript">.
<!doctype html>
<html>
<head>
<title>page</title>
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
</head>
<body>
<script>
function goToPage() {
var pageUrl = 'http://www.google.com/';
window.open(pageUrl);
}
</script>
<div id="installBtn" onclick="goToPage()">go to page</div>
</body>
</html>
The expected action is: when touch the div, a new window opens.
This code works great in the iPhone's safari.
But when I tap "+" -> "Add to Home Screen", and press "go to page", no window is opened, and the page loads in the same screen.
How to force, by javascript, a new window to open in the standalone mode?
The below question does mention a possible JavaScript solution out of the top voted answers, which constructs the anchor element and dispatches the 'click' event on it.
Question: Force link to open in mobile safari from a web app with javascript
Answer: https://stackoverflow.com/a/8833025/1441046
Alternatively if you can use an anchor element (I know you asked how to do it in JavaScript) you can do the following:
<a id="installBtn" href="http://www.google.com/" target="_blank">go to page</a>
Other related questions:
iPhone window.open(url, '_blank') does not open links in mobile Safari
This works for me. Doesn't work when requesting it from html, only from JS.
window.open('[url]','_system');
you can use childbrowser to open in the standalone mode
Or you can use this
window.location = url(your Url);
There you go! (if you still need it)
<script>
if(window.navigator.standalone === true)
document.write('Standalone');
else
document.write('Web browser');
</script>
R.