Javascript document.write in IE 8 - javascript

This is doing my head in, been chasing it all day. We have an ad server that calls a script on our site which then inserts code.
E.g.
Adserver page called in an iframe:
<html>
<head><title></title></head>
<body>
<script src="http://adserver/ad?s=728x90"></script>
</body>
</html>
The javascript returned by the script call above:
document.write('<script type=\'text/javascript\' src=\'http://partner.googleadservices.com/gampad/google_service.js\'>\n');
document.write('</script>\n');
document.write('<script type=\'text/javascript\'>\n');
document.write('GS_googleAddAdSenseService("ca-pub-xxxxxxxxxxxxxxxxxxx");\n');
document.write('GS_googleEnableAllServices();\n');
document.write('</script>\n');
document.write('<script type=\'text/javascript\'>\n');
document.write('GA_googleUseIframeRendering();\n');
document.write('</script>\n');
document.write('\n');
document.write('<script type=\'text/javascript\'>\n');
document.write('GA_googleFillSlotWithSize("ca-pub-xxxxxxxxxxxxxxxxxx", "Global_728x90", 728, 90);\n');
document.write('</script>\n');
This inserts Google Ad Manager ads onto our page. Problem is that the code doesn't work in IE 7 and 8, but works fine in Chrome, Firefox, Safari etc.
The "error" returned by IE is "Object Expected" and running it through IE's "Developer tools" doesn't help either.
I've tried a ton of things to get it working, splitting up the
It seems the error is happening whenever a GS_ or GA_ function is run, so I suspect IE is trying to stop external scripts from writing to the page?
Can anyone shed some light why the error is happening or a solution?
Thanks

I think it's simply because Chrome, Firefox, Safari etc., are faster browsers. They're downloading the file http://partner.googleadservices.com/gampad/google_service.js before executing the script that depends on it, whereas IE is still pulling the file at that point.
Perhaps you can include the contents of that js file in your own js somewhere?

I've seen this a lot since posting this question. As far as I understand it, it's a race condition problem that only exists in IE. Unfortunately there is no way around it.

Related

How do I prioritize which part of a page should load 1st?

Okay guys I have a website that has a lights off for videos source code: http://www.megaptery.com/allofthelights/
An organic tabs for videos using Jquery
and a 2buttons which onclick it changes the CSS of the whole page you know it's kinda like a theme for the page
Here is an example of one of my page:
http://myanimesekai.com/Watch/Noucome-Episode-9
okay all of them works perfectly fine on my laptop all of them IE, Mozilla and the OLD Google Chrome.
But Then I tried it on my Brothers Laptop BUT his Google Chrome is the latest Google Chrome the Google Chrome where the scrollbar changed. The problem is that the Lights off feature is malfunctioning it doesn't turn off the video only. But the Organic Tabs and The 2buttons works perfectly fine. So I tried it on an internet Cafe and this is where I was really frustrated their Google Chrome is also updated and then both 3 of them were malfunctioning then after a while I tried them on Mozilla and all of them worked perfectly fine and so I have an Idea maybe it's becaused it took time for the Jquery and my Javascript to load which is why all 3 of them were malfunctioning.
so my question is is there a way for me to make my page load the jquery and javascript 1st? or am I missing something that the new Google Chrome requires? this is really frustrating me
oh BTW the 2buttons that changes the CSS are the B and M squares Below the facebook page
There are so many errors on this page (http://myanimesekai.com/Watch/Noucome-Episode-9) that any one error can cause the page not to work.
You need to clean up your code quite a bit:
<script src="http://myanimesekai.com/javascript.js"></script>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="http://myanimesekai.com/organictabs.jquery.js"></script>
You are calling jQuery in your javascript.js file. The jQuery library has not been declared before your scripts. You need to restructure your code to (you only need one version of jQuery):
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="http://myanimesekai.com/javascript.js"></script>
<script src="http://myanimesekai.com/organictabs.jquery.js"></script>
This will fix some errors. I suggest that you look at the console for further errors and fix them.

JavaScript not working on Internet Explorer 10

I'm on Windows 7, and just upgraded IE to 10. It works fine, except that Javascript isn't working. I know that it is enabled, as I can go into the settings and disable it, and then I get the "no js" output. But with it enabled, I get nothing. No errors in the JS console. The same script in Firefox gives me "hello".
Browser Mode is "10" and Document Mode is "Standards", though changing these doesn't yield anything different. Here is the entire page:
<!DOCTYPE HTML>
<html>
<body>
<script type="text/javascript">
document.write('hello');
</script>
<noscript>no js</noscript>
</body>
</html>
Similar results on other websites -- if I go to a page that uses Disqus comments, I just get a blank space. If JS were disabled, Disqus would return a message saying so.
Thanks.
I solve this problem.
F12 -> Disable -> Script (uncheck)
I don't know if this will fix your problem but your markup is invalid, run it through the W3C Validator to fix the problems then try again.

Javascript suddenly stop working

I have asp.net project with Javascript code, i worked with Internet explorer 8, after i did finish the project i tried to run this project on All other browser (Chrom, Firefox, Opera, Safari) and suddenly each of these browser are not run javascript.
I was supprised that after 1 minutes i went back to the Internet Explorer and is also not running javascript.
I don't know what the problem, I've tried to comment partial of my javascript and it is not work, and comment all the left javascript and it's still doesn't work.
I have very long JavaScript code vith collaboration with AJAX, i have tried to remove paragraph by paragraph and it still doesnt work, i have tried to remove All the java script and run only "Hello word" simple java script code that fire from click event and it does not work. Although with other pages it work fine (alse the same "Hello word" simple code, the problem causes suddenlt til this moment every thing work fine. I attached sample code from the javascript code, it doesent metter because my there is a lot of java script code. Thank you every one that response i willi appreciation your response ! By the way there is none error, except when i click the button the java script write "
Better use some some browser plugins/integrations for checking javascript error. Try firebug in firefox or developer tools in IE. If you are doubtful of the path taken by your web application, try Fiddler to check your site.
If there is a referencing problem in case of master page usage or url routing usage or other then you can reference the javascripts and css in the following manner:
<link rel="stylesheet" type="text/css" href='<%= ResolveUrl("~/css/style.css") %>' />
<script type="text/javascript" src="<%= ResolveUrl("~/js/jquery-1.3.2.min.js") %>"></script>

inserting javascript in xslt not working in safari

I have a page that is pulling in an xml file uisng xslt. I need to add some javascript to it and have managed to get it all working in IE and FF but Safari is a no no. Here is the code I am using:
<SCRIPT LANGUAGE="javascript" DEFER="true">
<xsl:text disable-output-escaping="yes">
<![CDATA[
javascript here
]]>
</xsl:text>
</SCRIPT>
but I can;'t even get an alert in Safari?
Any ideas?
Try these couple of things first.
See if the code is even being rendered on the page and if it is being rendered correctly i.e no encoding problems, no weird characters etc.
If it is being rendered, try putting alerts and try catches around that code to see where exactly it is failing.
That will help you narrow down the problem.

$(document).ready doesn't work in IE

In my page there is two links, register and login.
The important one now is register. When I click it, it loads a .tpl file using jquery load function. In this tpl file I include a new js file with <script> ofcourse, and it works perfectly in safari, ff, opera and chrome, but of course, Why should it be working in IE?
So my question is, what should I do to make it working in IE? I think if I put the js in the .tpl file that would solve my problem, but if there is a better solution, I'd like to hear it. No this didn't help, so I guess there is no solution : D
Now I tried it with a simple alert, it worked perfectly.
My problem has changed. If there is a $(document).ready in the JS file the IE "ignores" the whole script, but if there isn't it works perfectly. The thing is that i need that document ready. : D
Thanks.
If the script is "ignored" if there's a $(document)ready then there may be an error in that block of the script and your IE is set to stop running scripts on error.
Try to simplify your issue a bit to try to pin point it. For example, copy the following code into a brand new html file and try it out (NOTE: you'll need to change the src path to the jquery.js file.)
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
alert('test');
}
</script>
</head>
<body>
</body>
</html>
Does the above work in IE for you or does it get ignored as well (again, after you update the path to the jquery.js file)?
If this works but it doesn't in your scenario, check your page's source in IE for how everything is loaded. The only time I've seen $(document).ready() throw an error is when the jquery.js file is not loaded prior to it or there's a conflict with the $() function...in which case you'll need the noConflict() function.
Make sure that the script tag is not in this form:
<script ... />
IE only accepts:
<script>...</script>
IE considers injection of script tags as a security issue. Change the script tag to:
document.write("<scri" + "pt src=...></scri" + "pt>");
Are you sure that your loaded javascript executes properly in IE. Perhaps it have a javascript quirk that is throwing an error and is making it appear as if it's not loading?
To test this out, non-dynamically including the javascript (include it in the page or similar) and set up a break-point in the script code and step through ot make sure it executes all the way through. Firebug would be an excellent tool for this.
I realise this is grasping at straws, but give it a try perhaps?

Categories

Resources