How would I get the current URL with a javascript code that could be used in a bookmarklet? This code isn't working:
javascript:copy(window.location.href);
It needs to copy it to the clipboard. I need to support Firefox, Chrome and IE
To get the URL from any legit browser (Opera, Chrome) with a bookmarklet:
javascript:(function(s){try{s=document.selection.createRange().text}catch(_){s=document.getSelection()}prompt('','\n'+location+'\n'+s)})()
If you want to add the Page Title:
javascript:(function(s){try{s=document.selection.createRange().text}catch(_){s=document.getSelection()}prompt('',document.title+" "+'\n'+location+'\n'+s)})()
What about a dialog from which you can copy the current URL?
javascript:void(prompt("URL:", location.href))
The void part prevents the browser from navigating away when pressing OK or Cancel.
Putting the URL into the clipboard takes more work, and differs on distinct browsers. If you really want to put the data in the clipboard, mention the browsers you need to support.
There is no built-in function in JS called copy. If there is one in the page, then it should work.
So the page would need this code
How do I copy to the clipboard in JavaScript?
Related
I am looking for how to execute javascript code in the URL bar via xJavascript.
The standard way would be xJavascript:JAVASCRIPTCODEHERE, you would remove the "x" and it would execute the code, but that is not working.
Am I doing it wrong, or is no longer possible?
Please help!
I'm not sure what browser you are on but this is what I use:
javascript: (() => { document.title = "Hello World";})();
It also might not be working because you are running it on a new tab (which doesn't work for chrome)
If you are using this feature frequirently, make a bookmark with javascript:... code.
If you want to run some random JS while editing this JS, use Devtools (F12 or Ctrl+Shift+I in browser), Sources tab on top, Snippets tab on left. Snippets are persistent, editable, may run on any page.
If you want to run the same code on every page of a website, try https://chrome.google.com/webstore/detail/user-javascript-and-css/nbhcbdghjpllgmfilhnhkllmkecfmpld or Tampermonkey
The requirement is I get URL of excel file in webservice response. I want to open this URL in new tab/window using javascript.
window.open(url, '_blank');
doesn't work in mac safari.
I also tried creating <a> with target="_blank" and trigger click.But it didn't work with Mac safari.
Is there any way to achieve the requirement?
Open the excel file in some specific div will also serve if it is possible.
Thanks.
Do you have a popup blocker installed ? if yes then read this . Safari/Chrome have built-in pop-up blockers that stop this from working. The only javascript that is allowed to open a new window in Safari/Chrome is javascript directly attached to click handlers (and other direct user input handlers). In past versions people figured out some ways to cheat (like generating some other element -- a form or div -- and simulating user input with javascript), but newer versions are smarter about detecting this. I'd recommend re-configuring things so that you don't use a delayed pop-up -- that is the kind of thing that can generally be jarring to a user after all.
I have a JavaScript string which I want to be downloaded when the user clicks a particular button.
I have got it to work on Firefox and Chrome using a data URI and creating a new anchor element which links to this data URI.
However, I found out that this way of doing it is not supported on IE due to security reasons.
Can someone tell me how can I download a file on clicking a button so that it works on IE using Vanilla JavaScript?
Thanks for your help.
Kevin
Is it possible create a button that can be used to paste some clipboard text into a textbox using javascript?
In my project I'm using ZeroClipboard to copy any text that I want, but now I need to paste that information using a single button in other page without any copy page connection.
At the internet I found ways to do that, but it just works on IE and I need a cross browser solution (minimun IE, chrome and FF).
Can anyone help me?
Other info:
I'm using asp.net mvc 3
For security reasons, Javascript don't have access to clipboard.
ZeroClipboard uses Flash in order to copy the text to clipboard BUT for security reasons too, Flash can only write to clipboard, not read.
The only way to do it is using a Java applet.
Here is article/Tutorial explaining how to do it : http://www.dynamic-tools.net/toolbox/copyToClipboard/
But the best pratice is to have a textarea with the data to copy already selected. Because some browser will not let you change the value of the clipboard data.
Is there a way to modify JavaScript code while debugging? Visual Studio has "Edit and Continue", and similar hot swapping of code can be done in Java and other languages. Can this be done with JavaScript, and if so, how?
Chrome, Safari, and some other WebKit-based browsers contain a feature in the Web Inspector known as Live Edit. If you go to the Scripts panel and are stopped on a breakpoint (or maybe even if not stopped on a breakpoint — I'm not sure), you can double click on a line and start editing that line. The changes you make will take effect on the script.
With Chrome Developer tools, this is super easy.
Just pop open inspector, click on the scripts tab, select which one you want from the dropdown menu and then you are free to edit the script and add in breakpoints. If you refresh the page, your breakpoints will stay there.
If you watch this talk but Paul Irish, he shows how you can edit a script on the fly
http://paulirish.com/2011/a-re-introduction-to-the-chrome-developer-tools/
also good:
http://blip.tv/jsconf/jsconf2011-paul-irish-5382827
If you're talking about while debugging, it's very easy to modify the running code. In your debugging console, you can enter in Javascript expressions and it will run in the context of the window, which contains all the objects and functions of your code, so you can swap them out by redefining them.
Because JavaScript can modify the DOM the you essentially have to change the JavaScript file, save it and reload. For me, I like IE so I run the webpage in a browser NOT IN DEBUG mode. Then you can change the script files, SAVE them. switch back to the browser and reload (F5) to see your changes. Supposedly IE 11 has this ability (probably like Chrome which is essentially what I am doing, changing saving reloading from what I can tell) but I can't get it to find, let alone open a js file. Super poor UI. I'm guessing the browser to open the file icon is but it is always grayed out.