How to add javascript file to <head> in this state?

Only if form action /?cms_mode=edit

 <body id="home"> <form method="post" action="/?cms_mode=edit" id="main"> </form> </body> 

then the js edit.js file should be added to the 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 this possible through jquery / javascript?

And the edit.js flie file should be added after all the other .js file

+4
source share
1 answer

If you need to do this on the client side in JavaScript, you can 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); } 
+4
source

All Articles