JavaScript - 'self Source' A Javascript File?
Is it possible to self source a javascript file?
I have a file with code that opens a javascript window and document.writes to it. I want to run some code in this file attached to window.onload. Code: function someWindow() { var openedWindow = open(/* relevant vars */); openedWindow.document.write(/*doctype and html head markup*/) openedWindow.document.write("<script type=\"text/javascript\" src=\"(this file)\"></script>"); openedWindow.document.write("<script type=\"text/javascript\">window.onload = function(){ /* sourced code */}</script>") openedWindow.document.write(/*html body markup*/) openedWindow.document.close(); } then in the same file have code defining object constructors and such that attach events to various elements. I realize I can write a long string variable with all the code, but that would be visible a browser window -> view source window ( I know it won't hide the code in a separate source file) The object is to have a widget all in one file, rather than having a separate html, css file and another javascript code file. Thanks for advice, suggestions, encouragement, JK Similar TutorialsHow does one go about swapping the Javascript Source file for another on when a checkbox is clicked, obviously the sources have to revert to their normal state on reload or unchecking the checkbox: this would be the original source: <script type="text/javascript" src="Includes/eng_chars.js"></script> it would be swapped for this souce file on checkbox checked: <script type="text/javascript" src="Includes/heb_chars.js"></script> and then returned to <script type="text/javascript" src="Includes/eng_chars.js"></script> when the checkbox is unchecked, page is reloaded or the the reset (clear form) button is pushed Thanks Hi there. I am not all that great at coding, but would like to put together a windows sidebar gadget that keeps track and logs specific activities. Some daily, some weekly, some monthly, ect. I need to find a way to refresh a small imported java script every time a button is pressed without refreshing the entire form. Would also like to have it refresh automatically every hour if possible. The line of code to reload is <script src="http://www.dgdevelco.com/quotes/quotestxt.js"></script>. Here is the entire code: <html> <head> <title>Form</title> <style> body { margin: 0; width: 130px; height: 400px; background-image: url(bg.jpg); } </style> <script type="text/javascript"> /*Enable Gadget Setting Functionality.*/ System.Gadget.settingsUI="settings.html"; </script> </head> <g:background style="position:absolute;top:0;left:0;z-index:-999;no=repeat;" /> <form name="Form"> <table width="128" style="position: absolute; left: 1px; top: 1px;"> <tr> <td><input type="checkbox" name="item" value="01"></td> <td style="font-family: 'Arial Narrow'; font-size: 10px;">Item 1</td> </tr> <tr> <td><input type="checkbox" name="item" value="02"></td> <td style="font-family: 'Arial Narrow'; font-size: 10px;">Item 2</td> </tr> <tr> <td><input type="checkbox" name="item" value="03"></td> <td style="font-family: 'Arial Narrow'; font-size: 10px;">Item 3</td> </tr> <tr> <td><input type="checkbox" name="item" value="04"></td> <td style="font-family: 'Arial Narrow'; font-size: 10px;">Item 4</td> </tr> <tr> <td><input type="checkbox" name="item" value="05"></td> <td style="font-family: 'Arial Narrow'; font-size: 10px;">Item 5</td> </tr> <tr> <td><input type="checkbox" name="item" value="06"></td> <td style="font-family: 'Arial Narrow'; font-size: 10px;">Item 6</td> </tr> <tr> <td><input type="checkbox" name="item" value="07"></td> <td style="font-family: 'Arial Narrow'; font-size: 10px;">Item 7</td> </tr> <tr> <td><input type="checkbox" name="item" value="08"></td> <td style="font-family: 'Arial Narrow'; font-size: 10px;">Item 8</td> </tr> <tr> <td><input type="checkbox" name="item" value="09"></td> <td style="font-family: 'Arial Narrow'; font-size: 10px;">Item 9</td> </tr> <tr> <td><input type="checkbox" name="item" value="10"></td> <td style="font-family: 'Arial Narrow'; font-size: 10px;">Item 10</td> </tr> <tr> <td colspan="2"> <input type="submit" value="Submit" style="font-family: 'Arial Narrow'; font-size: 10px; float: left;"> <input type="reset" value="Reset" style="font-family: 'Arial Narrow'; font-size: 10px; float: right;"> </td> </tr> <tr> <td colspan="2" align="right"> <input type="button" name="Report" value="Report" style="font-family: 'Arial Narrow'; font-size: 10px;"> </td> </tr> <tr> <td colspan="2"> <font style="font-family: 'Arial Narrow'; font-size: 10px; text-align: center;"> <script src="http://www.dgdevelco.com/quotes/quotestxt.js"></script> </font </td> </tr> </table> </body> </html> I have tried iframe and while it looks nice for text wrapping, it will still reload the entire gadget. Any suggestions (preferably simple so my little mind and wrap around it) would be great! Thanks for looking. :) Hello, i'm trying to insert a dynamic js file which contains multiple functions in it (for the example : function x, function y) and it seems that my google chrome doesn't really like it so much is there anyway you know i can bypass it and make it work and both web browsers code examples: // this is where the js file supposed to go <script id="ScriptFile"> </script> //1.js contains function x and function y document.getElementById('ScriptFile').src = "/Mysite/js/1.js" later on i need to preform some actions with function x & y. Couple more issues i need to explain first there are number of js files (1,2,3 .... n ) which all contain the same functions but with different data so i cant register them hard-coded if i type the function x into the "ScriptFile" block, it does work.. its not the function problem. same goes if i include it as source in the "ScriptFile" block (<script id="ScriptFile" src="/Mysite/js/1.js") this only gives me an error while using chrome, works perfectly fine under explorer the error says it cant find function x. thanks alot! I want to hide my JavaScript but when I checked the FAQ of this forum, I saw that it said that it isn't possible. But how did worldometers.info did it? Because I cant find the JavaScript source. hi- trying to set frame source from javascript- i cant get it to work.. Code: <script> stud = mm_adl_API.LMSGetValue("cmi.core.student_id"); newlink = ('https://blah.blah.blah&stud_id='+stud); // --> </script> <frameset rows="*,80" frameborder="no" border="0" framespacing="0"> <frame src="javascript:window.location(this.newlink)" name="thisname" /> <frame src="bottom.html" name="bottomFrame" scrolling="No" noresize="noresize" id="bottomFrame" title="Scorm Handling" onload="mm_adlOnload()" /> </frameset> How do I hide my javascript from html page (from view source on right click)?
Hi! I want to insert flash player on my page, that user can change flv source. But I dont know how to make input field that change flv source. I tried to insert input field and button but dont know how to make it working, please help me Here is my flvplayer embed code: <script type="text/javascript" src="http://flvplayer.com/free-flv-player/flvplayer/swfobject/swfobject.js"></script> <div id="embed_player"> <h1>Please Upgrade Your Flash Player</h1> <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p> </div> <script type="text/javascript"> var flashvars = { flvpFolderLocation: "http://flvplayer.com/free-flv-player/flvplayer/", flvpVideoSource: "http://flvplayer.com/media/audi_tdi_commercial.mp4", flvpWidth: "640", flvpHeight: "375", flvpInitVolume: "50", flvpTurnOnCorners: "true", flvpBgColor: "#FFFFFF" }; var params = { bgcolor: "#FFFFFF", menu: "true", allowfullscreen: "true" }; swfobject.embedSWF("http://flvplayer.com/free-flv-player/FlvPlayer.swf", "embed_player", "640", "375", "9.0.0", "http://flvplayer.com/free-flv-player/flvplayer/swfobject/expressInstall.swf", flashvars, params); </script> Hi - I'm working in ASP.Net 2.0. My page has a GridView control, which is populated by a SQLDataSource. The GridView has one Button control per row. The button has a client-side javascript function (ShowDelete) attached to its OnClientClick event on DataBinding of the GridView. This event fires some javascript. The javascript does 3 things: - It changes the text of the button from "Hide" to "Create" - It changes the background color of the button from red to green - It assigns a new onClientClick event to the button: "ShowAvailable" The text and the color of the button change with no problem. After I change the OnClientClick event, I send an alert with the button's OnClientClick event and it reports it to be "ShowAvailable". However, when I click on the button, it doesn't fire ShowAvailable, it fires the original onClientClick event (ShowDelete). Also, when I do View Source, it shows the button's text, color and OnClientClick event as their original settings, i.e., "Hidden", "Red" and "ShowDelete", even though I'm looking at a green button that says "Create." What's going on here? Here's the code I use to attach the OnClientClick event on DataBinding of the GridView: Code: foreach (GridViewRow row in this.gvLocation.Rows) { if (row.RowType == DataControlRowType.DataRow || row.RowType == DataControlRowType.EmptyDataRow) { int rowindex = row.RowIndex + 1; //to exclude the header which is counted as a row when we get to javascript btnAction.OnClientClick = "ShowDelete(" + rowindex.ToString() + "); return false"; } } Here's the javascript for ShowDelete: Code: function ShowDelete(rowindex) { var locationgridID = '<%= gvLocation.ClientID %>'; locationgrid = document.getElementById(locationgridID); if (locationgrid != null) { action_cell = locationgrid.rows[rowindex].cells[3]; for (k = 0; k < action_cell.childNodes.length; k++) { if (typeof(action_cell.childNodes[k].id) == 'string') { action_cell.childNodes[k].value = "Create"; action_cell.childNodes[k].style.backgroundColor = "Green"; action_cell.childNodes[k].onclientclick = "ShowAvailable(" + rowindex + "); return false"; alert(action_cell.childNodes[k].onclientclick); // reports the OnClientClick event is ShowAvailable } } } } Any thoughts are greatly appreciated! Hi, I know nothing about javascript but I was able to handle the instructions to install the login/password featu http://www.javascriptkit.com/script/...ginpass2.shtml works great! however, when someone views the source code, they're able to see what the password is. additionally they can see the url of the page it would take them if they entered the password. how do i protect against this vulnerability? thanks in advance! Let me give an example: javascript: var myvar=10; function myfunc(){}; void(0); After excuting the above js source code in the address bar of my browser, I can use window.myvar and window.myfunc() to access myvar and myfunc. This indicates that the above "address-bar javascript code" must have been stored somewhere in the current page. My question is: where is the "address-bar javascript code" stored in the current page? or equivalently, is it possible to retrieve the "address-bar javascript code" by using some other javascript codes? I checked document.childNodes and document.documentElement, but cannot find the javascript source code. Maybe the source code is stored in the window object? How to retrieve it? Thank you very much for the help! recently i noticed that all of my embedded JavaScript code and external style sheets are being shown IN "view source." this happens in all browsers ( IE, FF, Chrome, and Safari [windows]) ... oddly enough it only happens when viewing on my vista or win2k3 machines. is this something added to these OS's or the result of an installed program? has anyone seen this before? All -- I have a JavaScript config file called gameSetting.js which contains a bunch of variables which configures a particular game. I also have a shared JavaScript library which uses the variables in gameSetting.js, which I include like so: <script type="text/javascript" src="gameSetting.js" ></script> <script type="text/javascript" src="gameLibrary.js" ></script> In gameSetting.js I have: $(document).ready(function() { // call some functions / classes in gameLibrary.js } in Firefox, Safari, and Chrome, this works fine. However, in IE, when it's parsing gameSetting.js, it complains that the functions that live in gameLibrary.js aren't defined. When it gets to parsing gameLibrary.js, the variables in gameSetting.js are reported as not being defined. I've tried dynamically bootstrapping the gameLibrary file using this function in document.ready for dynamic load... $.getScript("gameLibrary.js"); However, the same problem still happens in IE, where when it parses the files individually it's not taking into context the file/variables that came before, so it's not an out of load order problem. My options a 1) collapsing all the functions in gameLibrary.js and variables in gameSetting.js into one file. However, this is not practical because this is dealing with literally hundreds of games, and having a gameLibrary.js in ONE location for ONE update is what makes most logical sense. 2) figure out a way to get this to work where variables in file1 are accessible to file2 in IE (as it seems they are in other browsers). jQuery seems to be able to have multiple plugins that all refer to the based jQuery-1.3.2.js, so I know there is a way to get this to work. Help appreciated. Nero Hi everyone, I have been trawling for useful info for a few hours and still have no definitive answer. There is plenty of info about creating server side javascript which can use php/asp to pull in xml etc and process but there is nothing I could find identifying how to do the same thing but with the javascript being client side only, e.g chrome plugin code. From what I currently understand, javascript client side only cannot reach or ask for any services externally. Am I missing something obvious or just trying to do something impossible? Cheers , Aro Very new to Javascript (been a HTML/CSS guy for a while, but never really got into more than tinkering with other other people's Javascript coding), but I came across a situation I can't find canned coding for, and trying to create it from bits and pieces I Googled has led me to a dead-end. In summary, I have a website that I frequently visit (FWIW, Firefox 3.x is my browser of choice) with many image sources referring to URLs that end with "-thumbnail.jpg". However, for better image quality, I am trying to use Greasemonkey to replace all instances of "-thumbnail.jpg" in the source of images on this site with "-bigthumbnail.jpg". The closest I could think of was to somehow use getElementsByTagName and innerHTML.replace, but realized that innerHTML does not do HTML, only content. Below is as far as I tried to get on my own, I appreciate any assistance from the folks here to help a JS novice like myself, thanks! Code: (function() { var as,ae; as = document.getElementsByTagName("img"); for (var i = 0; i < as.length; i++) { ae = as[i]; ae.innerHTML = ae.innerHTML.replace(/-thumbnail/gi, "-bigthumbnail"); } })(); Hey guys. This is vague because I dont know what exactly to tell you but please reply with me so I can fix this. I want to add something to my forum. Specifically, I want to add a HTML and Picture button for when you go to reply. Like posting an article here, there are also these options (font, alignment, insert image) I do not know how to achieve this but shouldnt be too hard. Here are the two sources you will need to look through to help me fix the forum. http://neoweather.com/FWFORUM.JS http://static.websimages.com/JS/fw.js THANKS I can get this code to take two separate sections of a file which are not beside each other and write them into another file. It always comes up as a single full line of the code instead of the sections I want. The code includes the student number first name last name and three results of assignments. I want the code to write the student number and three results of all the students into a file and then work out the average of the student results. Can you help? Code: try{ while (in.hasNextLine()) { String line = in.nextLine(); out.println( line); int i=0; if(!Character.isDigit(line.charAt(i))) { i++; } studentStringNumber = line.substring(0, i); String stringResult = line.substring(i); studentStringNumber = studentStringNumber.trim(); stringResults = stringResults.trim(); double stringResultsValue = Double.parseDouble(stringResults.trim()); stringResults = in.nextLine(); studentStringNumber = in.nextLine(); studentNumber = Integer.parseInt(studentStringNumber); if(in.hasNextInt()) { int value = in.nextInt(); } results = Double.parseDouble(stringResults); if(in.hasNextDouble()) { double value = in.nextDouble(); } Scanner lineScanner = new Scanner(line); studentStringNumber = lineScanner.next(); while(!lineScanner.hasNextDouble()) { studentStringNumber = studentStringNumber+ " " +lineScanner.next(); } stringResultsValue = lineScanner.nextDouble(); } } Hi i am using javascript for the first time and i have a problem .I have 2 files html and javascript file in seperate but i donot know how to make them work .the code is down below .Thanks in advance for help. HTML <!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <meta name="description" content="Instagram API - usage" /> <meta charset=utf-8 /> <title></title> </head> <body> <input id="lat_input" type="number" value="60.221374"/> <input id="lng_input" type="number" value="24.805391"/> <button id="search_location">Search</button><br/> <button id="get_popular">Get popular</button> <div id="images"></div> </body> </html> Javascript file // API DOCUMENTATION: // Instagram Developer Documentation var clientId = 'e7538f47e197479d8d32a63ae3ae4cd2'; $('#search_location').click(function () { getMediaByLocation($('#lat_input').val(), $('#lng_input').val()); }); $('#get_popular').click(function () { getPopularImages(); }); function getMediaByLocation(lat, lng) { var o = { lat: lat, lng: lng, client_id: clientId }; $.getJSON('https://api.instagram.com/v1/media/search?callback=?', o, function (response) { processImages(response.data); }); } function getPopularImages() { var o = { client_id: clientId }; $.getJSON('https://api.instagram.com/v1/media/popular?callback=?', o, function (response) { processImages(response.data); }); } function processImages(array) { $('#images').empty(); $.each(array, function (index, element) { var fs = $('<fieldset>').appendTo('#images'); $('<img>').attr('src', element.images.low_resolution.url).appendTo(fs); if (element.caption) { $('<pre>').text(element.caption.text).appendTo(fs); } $.each(element.comments.data, function (index, comment) { $('<pre>').text('Comment from ' + comment.from.full_name + ': ' + comment.text).appendTo(fs); }); }); } Does anyone know how to accomplish this? I got the html file to show but none of the text in the file will show.
Hi, I have the following code snippet: test.html ====== <script language="javascript" type="text/javascript"> var testVariable = "test"; </script> <script language="javascript" type="text/javascript" src="test.js"> </script> test.js ===== var testVariable = window.top.testVariable; In firefox, I'm able to access testvariable defined within test.html in test.js. But in chrome, test.js couldnot get the window.top.testVariable field defined in test.html. Can any one please let me know how i can make it work in chrome?. Am i missing something here?. Dear All I have a .js file in which i have pasted Urdu text and HTML tags like function urdutext() { innerHTML.right_column='HTML tags & urdu text';} The .js file contains about eighty lines of urdu text and some HTML tags in betweeen. But when i run this file alone in my browser it displays half of the file and the rest of the lines remain undisplayed. and when i use this file in my web page and when i click a button to display the urdu text, it dispays nothing in my web page. I know the reason but i cant solve it my self. The reason is that the .js file does not get fully uploaded and hence the file remains open and the syntax become wrong. And that is the reason it does not display anything in the web page. So i want ut help. Any one can help and would take my best wishes. Regards Sajad Bhatt |