jQuery for opening url in Flash - javascript

I have a little problem with opening links because I was using script
getURL("javascript: $(function(){$('#SCT_InnerContent').load('"+_root.linksDB[id][2]+"?lang=en');});");
in flash but it works only in Google Chrome.
Can anyone help me with reworking this script to run under other browsers as well?
Thanks in advance

Why not put the jQuery into a JavaScript function in the page, and then call that using ExternalInterface? This is the most robust way of communicating with browser JavaScript from within Flash.
Something like this in the page:
<script language="JavaScript">
function handleFlashCall(arg){
$(function(){$('#SCT_InnerContent').load('"+ arg +"?lang=en');});
}
</script>
And then, from within Flash:
ExternalInterface.call("handleFlashCall", _root.linksDB[id][2]);
See the explanation here:
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf626ae-7fe8.html#WS2db454920e96a9e51e63e3d11c0bf69084-7f31
And reference docs here:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html#call%28%29

Make sure you have allowScriptAccess flashvar parameter available and set to "always". Take a look at the wrapper html to set it.
Take a look at this documentation on the subject.

Related

Is it safe to remove javascript source?

I found a way to hide javascript source using jQuery by using this script.
<script type='text/javascript'>
$(function(){$("script").remove()});
</script>
I tested creating variables, changing is value programmatically, calling functions, and ajax and so far it runs smoothly according to what it is intended to do.
I asked this question to prevent future damage to the web site I am currently developing.
Anyone who found out and using this method?
I found a way to hide javascript source
No, this does not hide javascript source code. It simply removes all <script> elements from the DOM.
Is it safe?
For normal javascript scripts, that have already been executed, yes. You could damage other functionality that uses script elements, like some templating engines, though.
I want to prevent future damage to the web site I am currently developing.
Don't damage it now! Omit this script.

How to load dijit dialog in IE using javascript?

I have an application which contains dijit dialog and we are loading that dialog using .show method in all browsers like mozilla ,chrome,safari but when we do same with IE7,it says zoomChart is undefined .
Note : data-dojo-id="zoomChart"
Maybe it's the Problem, that the widget wasn't ready loaded at this time.
IE handles many things in other ways the Firefox, etc. What other browsers ignore, disturbs the Ie.
UPDATE1
Possible Solution:
This one is setup at the beginning of your Html-Page right afterwards the declaration for the Scripts. In the Init-Function you can load all Modules the you later want to use. dojo/ready and dojo/domReady guarants you, that all nessessary Scripts and Nodes are loaded BEFORE it starts.
<script type="text/javascript">
require(["dojo/ready"],function(ready){
ready(function(){
init();
});
});
function init(){
require(["dojo/domReady!"],function(){
zoomChart.show();
});
}
By the way - even with this minimum of code you paste in the comments its nearly impossible to say where the error lies. Please, if the Example above wont work fot you, post all of the code is related to the problem.
Here's a link to dojo/domReady which could be helpful for you:
http://dojotoolkit.org/reference-guide/1.8/dojo/domReady.html#dojo-domready
Regards

Moving div above another using Javascript/JQuery?

I've seen a lot about doing this in CSS (far from ideal), but I'm thinking of building a Chrome extension and it requires that a div is inserted prior to another (for clarification, I mean that when testing the extension I need to drag the div above the other using Chrome Dev Tools). Is there a way to do this upon page load using Javascript/JQuery (or some other way which can be done via Chrome Extension)?
In previous attempts I've tried using insertAfter()/insertBefore() and before() and had no luck (although I might be missing something obvious), so I guess another question is do these need to be used in a certain way within a Chrome Extension?
Thanks in advance for any help!
Here is a little demonstration.
The insertBefore code being used is this:
$("<div>").prop("id","between").insertBefore("#blah");
The first two jQuery functions just create the div element. If you want to move an existing one:
$("#existingDiv").insertBefore("#otherDiv");
And this should be pretty self-explanatory.
For plugins, load jQuery asynchronously. Something like this should do:
(function(){
var s = document.createElement('script');
s.src = 'http://code.jquery.com/jquery-1.8.2.min.js';
document.getElementsByTagName('head')[0].appendChild( s );
})();
jQuery has a very easy method to move one node before another, which you touched upon in your question:
BEFORE:
<div id="first"></div> <div id="second"></div>
$("#second").insertBefore("#first");
AFTER:
<div id="second"></div> <div id="first"></div>
As far as Chrome, you may want to do some digging to see if jQuery is loaded by the time you make your call or not

Best method of displaying an alternative on javascript crash

Im looking for a very general method of providing an alternative site to a Javascript heavy site (a link going to the old static site).
My current implementation is:
//<Some JS/HTML>
$(document).ready(function() {
//<Some JS Code>
$('#error').attr('style','display: none;');
});
//<Some html>
<div id="error">
<span>If you can see this, that means something went very very wrong. Click Here to use the old portal. Please contact some#email.com with this error and provide as much information as possible, thank you :) </span>
</div>
My current problem is that this is visible while the site is loading :(. Is there a better method?
I know i can try and add lots of trys and catchs (theres already several), but the problem is the primary clients are going to be using a mixture of clients between. FF2-FF3, all version in between, and IE5-IE6. The IE5 im just placing a messagebox and redirection if they try to load the site, im not even going to try and make that compatible.
And these old browsers just are not compatible with certain things.... I know i could add in an .onerror, but FF didn't add compatibility until FF6 which is to new for most of the clients. (although strangely, IE5.5 has it)
NOTE: Im just jQuery 1.7.1
The basic flow of the current operation is just when it finishes loading the initial javascript it hides the div.
You can use mainly CSS with a JS helper for this.
Put this JS code as close to the top of the document as you dare, preferibly after the charset declaration. You will need to include jQuery before this line or you can use standard JS (document.getElementByID('html-tag').className='js';, this assumes you've given the html tag an id of html-tag):
$('html').addClass('js');
Then you can write your CSS to take into account the fact that JS may or may not be available:
#error {
display : block;/*if no JavaScript is available then show this element*/
}
.js #error {
display : none;/*if JavaScript is available then hide this element*/
}
Here is a demo: http://jsfiddle.net/x4tjL/ (JSFiddle seems to be having problems right now, here is a JSBin: http://jsbin.com/ahezuc/edit#preview)
Update
Putting the JavaScript code as near the top of the document and not wrapping the code in a document.ready event handler allows you to minimize the "flash" of content that is common when trying to hide/show content based on JS.
A simple solution would be to detect all incompatible browsers and show the message to upgrade their browser or to redirect to non js site, something like:
for IE5 and 6
if ($.browser.msie && $.browser.version <= 6){
//show my message here
}

How can I implement a Javascript/HTML Playground with Javascript?

I would like to implement a simple Javascript Playground like jsFiddle and was wondering on the best way to achieve this. From the way jsfiddle works, it creates an iframe with the submitted HTML/Javascript code. The source of the iframe comes from a dynamically created page from the jsfiddle server.
I was wondering if it would be possible to do this with client side javascript code only. I have tried this but does not work (custom code is not executed and do not know if jquery is loaded in the iframe):
$iframe = $(document.createElement("iframe"))
$html = $iframe.contents().find("html")
//HTML code
$html.children("body").append($(htmlcode))
//Javascript code (first jquery and then custom code)
$script = $(document.createElement("script"))
$script.attr("src","jquery.js")
$html.children("head").append($script)
$script = $(document.createElement("script"))
$script.html(javascriptcode)
$html.children("head").append($script)
$iframe.appendTo($("body"));
You don't have to be that complex.
Just open a new window (or an iframe) and put your HTML inside it.
Demo: http://jsfiddle.net/DerekL/uSrU6/4 (UPDATED)
also I'm not completely sure I understand what exactly are you trying to do. I think you have a mistake in the code you posted:
You are trying to append the script to $html.children('head') while $html is not the $iframe itself but the contents.. I think contents() doesn't return a DOM element so the rest after that isn't valid anyway. edit - now I see in the comments that regular js does work for you so this probably ain't the problem
I vaguely remember there is an issue with cross site scripting when calling js libs from another domain in an iframe. Not sure about that
EDIT: Found it: here maybe this is the issue. There is also a solution here

Categories