inserting javascript in xslt not working in safari - javascript

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.

Related

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.

Hard to debug situation (or bug) in Opera

Ok, I'll do my best.
There's this page http://tiu.ru/image/tmp/test_2.html , which looks differently in Opera then in Chrome and Firefox (maybe others).
It evaluates a javascript code inside <div></div>, that does document.write("") of a piece of another HTML code with <script>, that evaluates JS code that asks Google Ads to write ads.
Google Ads writes it's container and container's content (which loads advertising from Yandex) ((maybe you'll need to disable adblock to see ads, but you can just view the screenshot)).
And the problem is that in Opera it writes that content outside the original div somehow.
Screenshot of result for Chrome:
Screenshot of result for Opera:
If you take that code inside document.write() and put it just as usual HTML code -- everything works well. See http://tiu.ru/image/tmp/test_3.html
I can't figure out how to debug that google ads code, that's why I ask for help. Thank you.
p.s.: you can save page to localhost somewhere and open it, ads won't be loaded, but DOM tree will be the same wrong.
Thank you very much!
Well, you add a script tag with document.write() that does document.write() to add the one that calls GA_googleFillSlot, which itself does document.write() to add a SCRIPT with SRC set to a doubleclick.net URL which calls back into google_ads.js to trigger another document.write() that adds an inline SCRIPT containing another document.write() call to add another external script, this time loading context.js from an.yandex.ru, and it looks like context.js also contains code to add yet two more external scripts to the document. But at this point the damage already happened: although a loading external script inserted with document.write() should block parsing, something odd happens when the doubleclick.net script loads and calls back into google_ads.js that makes Opera close the parent DIV.
Let's see what the DOM looks like the moment DoubleClick calls back to google_ads - by setting a breakpoint in GA_googleSetAdContentsBySlotForSync and using Opera Dragonfly. There we go: on entering this script, the DOM is still OK, the DIV is not closed - but when this script thread does document.write() to add <div id=google_ads_div_ru__context_informers_addon_360x90_ad_container> with comments, markup and scripts inside, something about that new content makes Opera believe it needs to close the former document.write()-inserted DIV. It's a parsing bug deep inside the handling of multiple nested document.write()s, I guess.
This will work fine with Opera's upcoming HTML5 parser. If at all possible for you, don't worry about it and wait until Opera 12 sorts it all out.
Opera has a strict XHTML parser. Try wrapping your javascript in CDATA tags so the parser will ignore the < and & characters as well as any other illegal characters in your script:
<script type="text/javascript">
/* <![CDATA[ */
// put your js code here
/* ]]> */
</script>

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>

Javascript document.write in IE 8

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.

$(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