Only if form action is /?cms_mode=edit
<body id="home">
<form method="post" action="/?cms_mode=edit" id="main">
</form>
</body>
then a js file edit.js should be added into head, otherwise not.
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="main.js"></script>
<script type="text/javascript" src="edit.js"></script>
</head>
Is it possible through jquery/javascript?
And edit.js flie should be added after all other .js file
If you have to do it on the client-side in JavaScript, you may want to try the following:
var newScript;
if (document.getElementById('main').action.indexOf('?cms_mode=edit') >= 0) {
newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = 'edit.js';
document.getElementsByTagName("head")[0].appendChild(newScript);
}
Related
When I load this page the script is not loading for some reason. What am I doing wrong here?
<html>
<head>
<title>hi</title>
<script language="JScript.Compact">
var script = document.createElement('script');
script.onload = function() {
alert("Script loaded and ready");
};
script.src = "http://192.168.1.106/js/min.js";
document.getElementsByTagName('head')[0].appendChild(script);
</script>
</head>
</html>
I think it is working but the alert doesn't get triggered because the script you refer to isn't loaded. Try it like this:
<!DOCTYPE html>
<html>
<head>
<link media="screen" href="style.css">
</head>
<body>
<p>…</p>
<img src="file.jpg" alt="" />
<script src="responsive-nav.min.js">
<script>
window.onload = function () {
console.log('Document loaded.');
function init();
function dosomething();
}
</script>
</body>
</html>
<script language="JScript.Compact">
The language attribute is obsolete, but browsers still support it.
Since you set it to an unrecognised language, browsers don't know how to execute it, so they ignore it.
Remove the language attribute.
How do I make an iframe load all parent window's scripts?
I was thinking something like this:
<!DOCTYPE html>
<html>
<head>
<script src="jquery.min.js"></script>
<script src="somethingelse.js"></script>
</head>
<body>
<iframe>
<html>
<head>
<script>
for (var i=0;i<window.parent.document.scripts.length;i++){
var script = window.parent.document.scripts[i];
//now it should append 'script' to document.scripts (this iframe scripts array)
}
</script>
</head>
<body>
</body>
</html>
</iframe>
</body>
</html>
PS: I made it as simple as possible. The real code is much bigger.
Try:
for (var i in window.parent.document.scripts){
var parentScript = window.parent.document.scripts[i];
var newScript = document.createElement('script');
if(parentScript.src)
newScript.src = parentScript.src;
if(parentScript.innerHTML)
newScript.innerHTML = parentScript.innerHTML;
document.head.appendChild(newScript);
}
I have the following snippet:
<html>
<head>
</head>
<body>
<form>
<div id='mydiv'>
</div>
</form>
</body>
</html>
I want to add "recaptcha" inside #mydiv usign a javascript code given at https://developers.google.com/recaptcha/docs/display just before </body>:
I tried to use the following code:
<script>
var mydiv = document.getElementById('mydiv');
var script = document.createElement('script');
script.type = "text/javascript";
script.src = 'http://www.google.com/recaptcha/api/challenge?k=6LeZBs8SAAAAAFnpP1frAONoZH-I-W9HOm0RQgV0';
mydiv.appendChild(script);
</script>
But it doesn't work. It only paste the script code. It doesn't run it.
Do you have any idea how to do this?
Thanks.
Here you go taken from the example code on your link see fiddle,
http://jsfiddle.net/GVwZ4/1/
in a div
http://jsfiddle.net/GVwZ4/2/
<body>
<script type="text/javascript"
src="http://www.google.com/recaptcha/api/challenge?k=6LeZBs8SAAAAAFnpP1frAONoZH-I- W9HOm0RQgV0">
</script>
<div></div>
</body>
I'm trying to include a separate .js file so I can pull in a class I created but it doesn't work, can someone tell me why?
playercharacter.js
function PlayerCharacter() {
this.x = 0;
this.y = 0;
this.dx = 5;
this.dy = 5;
}
PlayerCharacter.prototype.sayHello = function()
{
alert ('hello');
};
index.html
<html>
<head>
<script src="js/playercharacter.js" type="text/javascript" ></script>
</head>
<body>
<script type="text/javascript" >
var player = new PlayerCharacter();
player.sayHello();
</script>
</body>
</html>
You forgot wrap your JS-code into the <script> tags
<html>
<head>
<script src="js/playercharacter.js" type="text/javascript" ></script>
</head>
<body>
<script type="text/javascript" >
var player = new PlayerCharacter();
player.sayHello();
</script>
</body>
</html>
Your JavaScript code is not in a script tag.
<script>
var player = new PlayerCharacter();
player.sayHello();
</script>
You need to surround the code in the body with a <script> tag.
cannot run this code ... php textarea is showed but only one click and everything is disappear
Note:the page is positioning by anchors and words in "{}" are tags.
On оne page I am trying to put more than one ACEtextarea
(jQuery function is just a thought)
<div id="{id_area}" style="width:100%;height:165px; position:relative; background:#fff;" class="">
{text}
</div>
<input type="hidden" name="{name}" id="{id_area}-textarea"/>
<script src="{dir}/src/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="{dir}/src/theme-crimson_editor.js" type="text/javascript" charset="utf-8"></script>
<script src="{dir}/src/mode-php.js" type="text/javascript" charset="utf-8"></script>
<script>
window.onload = function() {
var editor_{id_area} = ace.edit("{id_area}");
editor_{id_area}.setTheme("ace/theme/crimson_editor");
var {id_area}_Mode = require("ace/mode/php").Mode;
editor_{id_area}.getSession().setMode(new {id_area}_Mode());
jQuery("#{id_area}-textarea").val(editor_{id_area}.getSession().getValue());
};
</script>